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

Spencer Graves spencer.graves at pdf.com
Mon Jul 14 18:44:05 CEST 2003


which(is.na(x))

hope this helps.  spencer graves

David Andel wrote:
> 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