Re: [R] Replace selected columns of a dataframe with NA

2011-06-20 Thread Dimitris Rizopoulos
I don't know if you have factors in your data frame, but in any case, you can try the following approach: mydata <- data.frame(id = 1:10, x = rnorm(10, 80), z = rnorm(10, 80), w = gl(2, 5)) mydata f <- function (x) { if (is.numeric(x)) x[x > 80] <- NA x } mydata[-1] <- lappl

[R] Replace selected columns of a dataframe with NA

2011-06-20 Thread Chris Beeley
I am using the following command to replace all the missing values and assorted typos in a dataframe with NA: mydata[mydata>80]=NA The problem is that the first column contains values which should be more than 80, so really I want to do it just for mydata[,2:length(mydata)] I can't seem to re-wr