[R] Subsetting data frame problem....

From: Marko Milicic <milicic.marko_at_gmail.com>
Date: Wed, 2 Jan 2008 01:50:05 +0000


Dear R users,

I'm new but already fascinated R user so please forgive for my ignorance. I have the problem, I read most of help pages but couldn't find the solution. The problem follows....

I have large data set 10,000 rows and more than 100 columns... Say something like

var1,var2,var2,var4.......var120


12,12,345,657,67,8.....
12,12,345,657,0,8.....
NA,12,345,657,NA,8.....
12,12,NA,657,67,8.....
12,12,345,657,NA,8.....

I would like to select only rows where all variables are not NA.... so I can do something like

df <- subset(

                              df
                              , !is.na(var1) & !is.na(var2) &
!is.na(var3) & !is.na(var4) & !is.na(var5)......................
                          );


But that would be very bad solution because I have more than 100 variables and if would be lengthy code to maintan..... also, it might be error prone programming style...Am I right?

my question is if there is some smarter way of doing this which would work even if I have 1000 variables???



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 Wed 02 Jan 2008 - 01:55:51 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 Wed 02 Jan 2008 - 04:30:05 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