[R] removing NA from a data frame

Ben Bolker bolker at ufl.edu
Fri Mar 17 23:33:31 CET 2006

Sam Steingold <sds <at> podval.org> writes:

> Hi,
> It appears that deal does not support missing values (NA), so I need to
> remove them (NAs) from my data frame.
> how do I do this?
> (I am very new to R, so a detailed step-by-step
> explanation with code samples would be nice).

  If you wanted to remove rows with NAs from data frame X
na.omit(X) would do it.

  In this case I think


 should work, although I haven't tested it.
function(z)any(is.na(z)) looks for any NA values
sapply applies the function to each element
in the list (= column in the data frame) and
returns a vector
! negates the logical vector
[] picks the appropriate elements (=columns) out
of the list (=dataframe)

  I haven't tested it.




 would work too, although I'm not sure.


More information about the R-help mailing list