[R] subsetting by NA

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Feb 25 18:08:17 CET 2005


See ?is.na

Uwe Ligges

Benjamin M. Osborne wrote:

> I want to know where all the NAs are in a matrix.  The data frame looks like
> this:
> 
> 
>>vmc[1:5,]
> 
>        date year month day snow.new prcp      tmin snow.dep       tmax
> 1 01NOV1954 1954    11   1       NA   NA -14.44444       NA 12.2222222
> 2 02NOV1954 1954    11   2       NA   NA -13.88889       NA  2.2222222
> 3 03NOV1954 1954    11   3       NA   NA -16.66667       NA -1.1111111
> 4 04NOV1954 1954    11   4       NA   NA        NA       NA -0.5555556
> 5 05NOV1954 1954    11   5       NA   NA -17.22222       NA -2.7777778
>        tmean yearmo
> 1  -1.111111 195411
> 2  -5.833333 195411
> 3  -8.888889 195411
> 4         NA 195411
> 5 -10.000000 195411
> 
> 
> This does not work:
> 
>>subset(vmc, snow.new==NA)
> 
>  [1] date     year     month    day      snow.new prcp     tmin     snow.dep
>  [9] tmax     tmean    yearmo
> <0 rows> (or 0-length row.names)
> 
> 
> Because:
> 
>>NA==NA
> 
> [1] NA
> 
> How can I return all rows of this data frame that contain NA in a particular
> field?
> 
> Thanks,
> Ben Osborne
>




More information about the R-help mailing list