[R] "which" for NA's (and FALSE's)

David Andel andel at ifi.unizh.ch
Mon Jul 14 18:31:29 CEST 2003


I need to know the position of the NA's in a matrix but it is resisting my 
approaches.

The problem shows already with a simple vector:

> x <- c(TRUE,NA,FALSE,TRUE)
> x
[1]  TRUE    NA FALSE  TRUE
> which(x)
[1] 1 4
> x[x==T]
[1] TRUE   NA TRUE
> x[x==NA]
[1] NA NA NA NA
> x[x=="NA"]
[1] NA
> x[x==F]
[1]    NA FALSE

How can I get just the position (2) for NA and (3) for FALSE as I do with 
"which(x)" for TRUE?

Thanks,
David




More information about the R-help mailing list