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

Chuck Cleland ccleland at optonline.net
Thu Feb 14 14:09:13 CET 2008


On 2/14/2008 7:59 AM, 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?

mymat[,which(colMeans(is.na(mymat)) < 1)]

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

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894



More information about the R-help mailing list