[R] removing NA values from data frame & identification function
ben at zoo.ufl.edu
Thu Apr 20 04:14:22 CEST 2000
On Wed, 19 Apr 2000, Faheem Mitha wrote:
> Dear people,
> 1) I have a data frame with named columns.For concreteness, let us say
> that I created a data frame from the vectors fee, fi fo, fum by
> giant.df <- cbind(fee, fi, fo, fum)
> Now, some of the entries in fee, fi fo fum are NAs. I want to remove any
> row which contains a NA, thus creating a new, smaller data frame, with the
> same column names. This seems like something people would need to do all
> the time, but I have been unable to think of a clean way to do it.
clean.df <- giant.df[apply(giant.df,1,function(z)all(!is.na(z))),]
would do what you wanted?
Or, slightly more tersely,
> Actually, I'm trying to do this because step and stepAIC don't seem to
> happy with handling glm objects constructed from data sets containing
> NAs. It would be even cooler if this could be done at the level of
> read.table, but I don't see a way to do this.
Ben Bolker bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
318 Carr Hall/Box 118525 tel: (352) 392-5697
Gainesville, FL 32611-8525 fax: (352) 392-3704
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