[R] removing NA values from data frame & identification function
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu Apr 20 12:49:23 CEST 2000
Faheem Mitha <faheem at email.unc.edu> writes:
> 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.
This would seem to do what you want:
giant.df.clean <- na.omit(giant.df)
or
subset(giant.df, complete.cases(giant.df))
or
giant.df[complete.cases(giant.df),]
However, this works on data frames and your giant.df is a matrix,
*not* a data frame. Use
giant.df <- data.frame(fee, fi, fo, fum)
and then go for the golden easter eggs...
--
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