[R] subset with NA

Roger Peng rpeng at stat.ucla.edu
Thu Feb 20 02:41:05 CET 2003


If `temp' is your data frame and `tuna' is a variable in `temp', then try

subset(temp, is.na(tuna))

-roger
_______________________________
UCLA Department of Statistics
rpeng at stat.ucla.edu
http://www.stat.ucla.edu/~rpeng

On Wed, 19 Feb 2003, Robert Schick wrote:

> Easy question that I can't find an answer for. I'm trying to subset a
> data frame and want to exclude the positive values, i.e. I want the NA
> values. 
> 
> My data:
> > summary(temp$tuna)
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
>       1       2       3       3       4       5    1211 
> 
> Querying for 
> subset(temp, tuna %in% "NA", select....
> subset(temp, tuna == NA, select....
> subset(temp, tuna == as.character(NA), select....
> 
> All yield an empty data frame.
> 
> An R-help post
> (http://www.r-project.org/nocvs/mail/r-help/2002/3645.html) suggested
> looking at http://developer.r-project.org/150update.txt, which I did
> but I'm confused as to how to accurately query for an NA string.
> 
> 
> -- 
> Rob Schick
> Ecologist
> NOAA Fisheries
> Santa Cruz Lab
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: 831.420.3960
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list