s-news
[Top] [All Lists]

Name mangling when using ifelse

To: s-news@lists.biostat.wustl.edu
Subject: Name mangling when using ifelse
From: "David Kane <David Kane" <a296180@mica.fmr.com>
Date: Mon, 30 Apr 2001 17:45:32 -0400 (EDT)
Reply-to: a296180@mica.fmr.com
My appearance of variable names within a dataframe get mangled when I use 
ifelse, sometimes.

> version
Version 6.0 Release 1 for Sun SPARC, SunOS 5.6 : 2000 
> df <- data.frame(x = 1:3)
> df
  x 
1 1
2 2
3 3
> df$new <- ifelse(df["x"] > 2, 1, 0)
> df
  x new.x                       # Why is this "new.x" instead of "new"? 
1 1     0
2 2     0
3 3     1
> names(df)
[1] "x"   "new"
> df$new
  x 
1 0
2 0
3 1
> df$new.x
NULL

So, I think that df is as it should be. Is there a way that I can get it to
display correctly?

Thanks,

Dave Kane

<Prev in Thread] Current Thread [Next in Thread>