[R] ifelse

juli g. pausas juli at ceam.es
Mon May 13 15:23:46 CEST 2002


I suppose this is a very basic question, but I cannot understant it:

> aa <- data.frame(x = c(rep("x", 3), NA, NA, NA), y= 1:6)
> aa$x[4]
[1] <NA>
Levels:  x
> aa$y[4]
[1] 4
> aa$y[4] <- ifelse(aa$x[4]=="x", NA, aa$y[4])
> aa$y[4]
[1] NA
>

I was expecting aa$y[4] not to be changed, but I may missundertood
something.

aa2 <- data.frame(x = c(rep("x", 3), rep("b", 3)), y= 1:6)
aa2$y <- ifelse(aa2$x=="x", NA, aa2$y)

this works OK

(R 1.5.0 on Windows)

juli

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list