Hi all, Ive got a database with 10 columns (different variables) for 100 subjects, each column with different # of NA's. I'd like to know if it is possible to use a function to exclude the NA's using only a specific column, lets say: Data2 <- omit.exclude(Data1$column1) ??, then Data3 <- omit.exclude(Data1$column2) and so on I tried the code above but with no results Thanks for any help CM __________________________________ Yahoo! SiteBuilder - Free, easy-to-use web site design software
dat <- data.frame(x=c(1,NA,2,2),y=c(3,2,NA,1)) dat dat[rownames(na.omit(dat[,"y",drop=F])),]> dat <- data.frame(x=c(1,NA,2,2),y=c(3,2,NA,1)) > datx y 1 1 3 2 NA 2 3 2 NA 4 2 1> dat[rownames(na.omit(dat[,"y",drop=F])),]x y 1 1 3 2 NA 2 4 2 1 HTH, Jerome On August 7, 2003 01:05 pm, Christian Mora wrote:> Hi all, > > Ive got a database with 10 columns (different > variables) for 100 subjects, each column with > different # of NA's. I'd like to know if it is > possible to use a function to exclude the NA's using > only a specific column, lets say: > > Data2 <- omit.exclude(Data1$column1) ??, then > Data3 <- omit.exclude(Data1$column2) and so on > > I tried the code above but with no results > > Thanks for any help > > CM > > __________________________________ > > Yahoo! SiteBuilder - Free, easy-to-use web site design software > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Christian Mora wrote:> Hi all, > > Ive got a database with 10 columns (different > variables) for 100 subjects, each column with > different # of NA's. I'd like to know if it is > possible to use a function to exclude the NA's using > only a specific column, lets say: > > Data2 <- omit.exclude(Data1$column1) ??, then > Data3 <- omit.exclude(Data1$column2) and so on >I use indexing for that. Data2 <- Data1[!is.na(Data1$column1),] nb - don't use this: # WRONG WRONG WRONG! Data2 <- Data1[! (Data1$column1 == NA),] NA means you don't know. Therefore, it doesn't equal anything, including NA. For example, I don't know your birthday, and I don't know Napoleon's birthday. That doesn't mean you two have the same birthday, even though they'd both be represented as NA. Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz