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 ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.