Skip to content
Prev 303445 / 398513 Next

Subsetting with missing data

It makes sense if you think it through.  Your index vector is

 a$y==0
 [1] FALSE  TRUE    NA FALSE  TRUE    NA    NA FALSE FALSE  TRUE

and ?"[" says

NAs in indexing:

     When extracting, a numerical, logical or character 'NA' index
     picks an unknown element and so returns 'NA' in the corresponding
     element of a logical, integer, numeric, complex or character
     result, and 'NULL' for a list.  (It returns '00' for a raw
     result.]

so this is what one has to expect. Here are a couple alternatives for
getting what you want.

a[which(a$y==0),]
a[a$y %in% 0,]

Best,
Ista
On Wed, Aug 15, 2012 at 4:06 PM, Robin Jeffries <rjeffries at ucla.edu> wrote: