s-news
[Top] [All Lists]

Re: S-PLUS: na.omit on data.frame columns

To: "'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>
Subject: Re: S-PLUS: na.omit on data.frame columns
From: Bill Osburn <bosburn@sjrwmd.com>
Date: Mon, 2 Feb 2009 14:32:01 -0500
Accept-language: en-US
Acceptlanguage: en-US
Thread-index: AcmFbOwNAKzEzW7YQ0i/6hgqh4IIyw==
Thread-topic: RE: S-PLUS: na.omit on data.frame columns

Two nice answers

1)

mydf <- mydf[,which(apply(mydf,2, function(x) is.element(NA,x))==F)]

Be aware though that this will transform your data frame into a vector if only one column has no NA values.

 

From: Sebastien Bihorel, PharmD, PhD

 

2)

If all your data (x) are numeric, then try

 

y <- x[,!is.na(colSums(x))]

 

From: Kenton D. Juhlin

 

 

Both worked nicely

 

Thanks

<Prev in Thread] Current Thread [Next in Thread>