[R] Removing columns that are all NA from a matrix

Gabor Csardi csardi at rmki.kfki.hu
Thu Feb 14 14:06:16 CET 2008


data <- data[ , !apply(is.na(data), 2, all)]

(or something like that)

G.

On Thu, Feb 14, 2008 at 12:59:46PM +0000, Martin Waller wrote:
> Hi,
> 
> I guess this might be a FAQ or something, and there's probably a nice 
> simple way to do it, but I can't think of it:
> 
> Given a matrix, I want to remove columns that are _entirely_ filled with 
> NAs (partial NAs are fine).
> 
> How please?
> 
> Thanks,
> 
> Martin
> 
> ______________________________________________
> R-help at 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.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    UNIL DGM



More information about the R-help mailing list