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

Jerome Asselin jerome at hivnet.ubc.ca
Mon Jul 14 18:42:21 CEST 2003


> which(is.na(x))
[1] 2
> which(!x)
[1] 3

HTH,
Jerome

On July 14, 2003 09:31 am, David Andel wrote:
> Content-Length: 572
> Status: R
> X-Status: N
>
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list