[R] help: how to get the position of a value in a matrix
Liaw, Andy
andy_liaw at merck.com
Thu Jul 14 01:33:48 CEST 2005
Use which(..., arr.ind=TRUE); e.g.,
> m <- matrix(runif(12), 3, 4)
> which(m > .8, arr.ind=TRUE)
row col
[1,] 1 3
[2,] 2 3
[3,] 3 3
[4,] 3 4
> m
[,1] [,2] [,3] [,4]
[1,] 0.2148183 0.08251853 0.9444718 0.4487148
[2,] 0.5386863 0.49673282 0.8054240 0.5101593
[3,] 0.6252847 0.70974516 0.8858951 0.8590655
Andy
> From: wu sz
>
> Hello,
>
> I have a data set matrix of 1200 * 15. How can I get the position of a
> specific value in the matrix?
>
> I use "seq(along = x)[x > value]" to look for the position of the
> value in the matrix, but "seq" can just find the sequence position row
> by row in the matrix, not a real position (like "rowNumber,
> colNumber"). Is any function for that?
>
> Thank you,
> Shengzhe
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>
More information about the R-help
mailing list