[R] deleting specified NA values

Andy Bunn abunn at whrc.org
Mon Nov 1 16:42:49 CET 2004


I think you want something like so:

# make some data
foo.df <- data.frame(x = 1:100, y = runif(100), age = rnorm(100, 10, 1))
# stick some "real" NAs in all columns
foo.df[c(2,78,32,56),] <- NA
# make some "errant" NAs in the column age
foo.df$age[c(99, 26, 75, 3)] <- NA
# eg
foo.df[1:5,]
# remove the errant NAs with is.na
foo.df <- foo.df[!(is.na(foo.df$age) == T & is.na(foo.df$x) == F),]
foo.df[1:5,]




More information about the R-help mailing list