Dear R-users
I am trying to replace specific factor level values in a data frame
with NAs. The data frame includes different kind of variables (e.g,
characters, numbers, and factors). I'd like to replace all 'Not
applicable', 'Invalid', 'and Missing' for NA.
For example:
f.level <- c('Yes', 'No', 'Not applicable', 'Invalid', 'Missing')
df <- data.frame(x1=runif(100), x2=sample(f.level, 100, replace=T),
x3=sample(f.level, 100, replace=T))
I try changing the values by
df[df %in% c('Not applicable', 'Invalid', 'Missing'), ] <- NA
but nothing seems to change
summary(df)
My data frame has many more factors. Any advice?
Thank you,
Daniel
______________________________________________
[email protected] 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.