[R] column-wise deletion in data-frames

From: <jhainm_at_fas.harvard.edu>
Date: Mon 18 Jul 2005 - 22:38:31 EST


Hi,

I have a huge dataframe and like to delete all those variables from it that that have NAs. The deletion of vars should be done column-wise, and not row-wise as na.omit would do it, because I have some vars that have NAs for all rows thus using na.omit I would end up with no obs. Is there a convenient way to do this R?

To make the question more explicit. Imagine a dataset that looks something like this (but much bigger)

X1 <- rnorm(1000)
X2 <- c(rep(NA,1000))
X3 <- rnorm(1000)
X4 <- c(rep(NA,499),1,44,rep(NA,499))
X5 <- rnorm(1000)

data <- as.data.frame(cbind(X1,X2,X3,X4,X5))

So only X1, X3 and X5 are vars without any NAs and there are some vars (X2 and X4 stacked in between that have NAs). Now, how can I extract those former vars in a new dataset or remove all those latter vars in between that have NAs (without missing a single row)?

Thank you very much!

Best,
jens



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Jul 18 22:43:28 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:46 EST