[R] Subsets without NA

John Fox jfox at mcmaster.ca
Tue Jan 8 18:02:47 CET 2002


Dear Mikkel,

A very simple solution is to use na.omit; that is

   x2 <- na.omit(x)

produces a copy of the data frame x with all rows that contain missing data 
removed. The function na.exclude could be used also.

John

At 03:09 AM 1/8/2002 -0800, Grum, Mikkel wrote:
>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.

-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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