[R] Subsets without NA

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Jan 8 12:51:18 CET 2002


"Grum, Mikkel" <M.GRUM at CGIAR.ORG> writes:

> Is there a way of removing all rows with missing values from a data frame?
> I usually use 
> subset(x, var1!="NA") 
> and repeat for each variable.  It would be nice to be able to do it in one
> fell swoop.  Also, surprisingly, it doesn't always work.  Sometimes I'm left
> with an empty set even though not all rows have missing values for the
> variable.

subset(x,complete.cases(x)) or x[complete.cases(x),]

BTW: is.na(x) is preferable to x != "NA"

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list