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
> 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
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