[R] NA-values and logical operation
Patrick Hausmann
Patrick.Hausmann at uni-bremen.de
Tue Jan 13 11:58:45 CET 2009
Dear list,
as a result of a logical operation I want to assign
a new variable to a DF with NA-values.
z <- data.frame( x = c(5,6,5,NA,7,5,4,NA),
y = c(1,2,2,2,2,2,2,2) )
p <- (z$x <= 5) & (z$y == 1)
p
z[p, "p1"] <-5
z
# ok, this works fine
z <- z[,-3]
p <- (z$x <= 5) & (z$y == 2)
p
z[p, "p2"] <-5
z
# this failed... - how can I assign the value '5' to the new
# var "p2"
Thanks for any help!!
Patrick
More information about the R-help
mailing list