s-news
[Top] [All Lists]

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

To: Bill Osburn <bosburn@sjrwmd.com>
Subject: Re: S-PLUS: na.omit on data.frame columns
From: Sebastien Bihorel <Sebastien.Bihorel@cognigencorp.com>
Date: Mon, 02 Feb 2009 14:23:17 -0500
Cc: "'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>
In-reply-to: <9E9563D3FAECF9448B370F988FD6BD153A293695E4@MAILSVR.sjrwmd.com>
References: <9E9563D3FAECF9448B370F988FD6BD153A293695E4@MAILSVR.sjrwmd.com>
User-agent: Thunderbird 2.0.0.9 (Windows/20071031)
Hi,

If mydf is your dataframe, this should do the trick: 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.

Hope it helps

Sebastien Bihorel, PharmD, PhD
PKPD Scientist
Cognigen Corp
Email: sebastien.bihorel@cognigencorp.com
Phone: (716) 633-3463 ext. 323


Bill Osburn wrote:

I have a data.frame and want to remove all columns where there is an NA. So far I can only get na.omit to work on rows.

 

After googling for several hours I still can’t locate any ideas. Has anyone done na.omit or something, on columns?

 

With my current data.frame I should go from 16x78 to 16x28

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