Pat Schmitz wrote:
> Both vector query's can select the values from the data.frame as written,
> however in the first form assigning a value to said selected numbers fails.
>  Can you explain the reason this fails?
> 
> dat <- data.frame(index = 1:10, Value = c(1:4, NA, 6, NA, 8:10))
> 
> dat$Value[dat$Value == "NA"] <- 1 #Why does this  fails to work,
> dat$Value[dat$Value %in% NA] <- 1 #While this does work?
> 
> 
> #Particularly when str() results in an equivalent class
> dat <- data.frame(index = 1:10, Value = c(1:4, NA, 6, NA, 8:10))
> str(dat$Value[dat$Value %in% NA])
> str(dat$Value[dat$Value == "NA"])

1. NA and "NA" are very different things
2. checkout is.na() and its help page



-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
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.

Reply via email to