[R] Question about 'NA'

Jason Turner jasont at indigoindustrial.co.nz
Thu Aug 7 22:29:18 CEST 2003


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




More information about the R-help mailing list