Re: [R] Remove rows with NA across all columns

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Thu, 14 Feb 2008 21:03:08 -0800

Learn to use the power and flexibility of R subscripting.

## Warning:untested

apply(df,1,function(x)any(!is.na(x)))

gives TRUE for all rows that aren't all NA's.

So stick this expression into the 1st coordinate of a subscript for the df:

df[apply(df,1,function(x)any(!is.na(x))),]

Cheers,
Bert Gunter
Genentech

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of joseph
Sent: Thursday, February 14, 2008 8:53 PM To: r-help_at_r-project.org
Cc: r-help_at_r-project.org
Subject: [R] Remove rows with NA across all columns

Hi
I have a data frame df with 3 columns. Some rows are NA across all 3 columns. How can I remove rows with NA across all columns?  df=data.frame(col1=c(1:3,NA,NA,4),col2=c(7:9,NA,NA,NA),col3=c(2:4,NA,NA,4)) Thanks
Joseph  




Be a better friend, newshound, and

        [[alternative HTML version deleted]]



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.

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. Received on Fri 15 Feb 2008 - 05:07:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Feb 2008 - 05:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive