Faheem Mitha
2000-Apr-20 00:07 UTC
[R] removing NA values from data frame & identification function
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. 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. 2) Is there a function to compare whether two objects are identical in every respect? Thanks for everyone's very valuable help on this list. I'm still a raw beginner, but perhaps getting a little less raw... Sincerely, Faheem Mitha. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Ben Bolker
2000-Apr-20 02:14 UTC
[R] removing NA values from data frame & identification function
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.perhaps clean.df <- giant.df[apply(giant.df,1,function(z)all(!is.na(z))),] would do what you wanted? Or, slightly more tersely, giant.df[!(apply(is.na(giant.df),1,any)),]> > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2000-Apr-20 10:49 UTC
[R] removing NA values from data frame & identification function
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._