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: David L Lorenz <lorenz@usgs.gov>
Date: Mon, 2 Feb 2009 13:20:47 -0600
Cc: "'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>, s-news-owner@lists.biostat.wustl.edu
In-reply-to: <9E9563D3FAECF9448B370F988FD6BD153A293695E4@MAILSVR.sjrwmd.com>
References: <9E9563D3FAECF9448B370F988FD6BD153A293695E4@MAILSVR.sjrwmd.com>

Bill,
  How about

as.data.frame(lapply(DF, function(x) if(any(is.na(x))) NULL else x))

where DF is the name of your data.frame.
Dave




Bill Osburn <bosburn@sjrwmd.com>
Sent by: s-news-owner@lists.biostat.wustl.edu

02/02/2009 01:12 PM

To
"'s-news@lists.biostat.wustl.edu'" <s-news@lists.biostat.wustl.edu>
cc
Subject
[S] S-PLUS: na.omit on data.frame columns





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>