Re: [R] help: how to get the position of a value in a matrix

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Thu 14 Jul 2005 - 09:33:48 EST


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



R-help@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 Received on Thu Jul 14 09:37:08 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:38 EST