[R] NA when indexing vectors

Szilard szilard.mailinglists at gmail.com
Thu May 21 20:28:58 CEST 2009


Hello:

Is there a more natural way to get all elements that satisfy a condition
when there are NAs in the sample?

> x=c(1,2,NA)

> x>=2
[1] FALSE  TRUE    NA

> x[x>=2]
[1]  2 NA         ## I would expect here to get just "2"

> x[!is.na(x) & x>=2]   ## seems a bit cumbersome
[1] 2

Thanks,
Szilard




More information about the R-help mailing list