[R] Index of item in matrix

Spencer Graves spencer.graves at pdf.com
Thu Apr 3 06:40:14 CEST 2003


Satisfying what conditions?

Does the following example help you get what you want?

 > set.seed(1)
 > A <- array(rnorm(12), dim=c(3,4))
 >
 > sel <- (round(A)==1)
 > sel
       [,1]  [,2]  [,3]  [,4]
[1,] FALSE FALSE FALSE  TRUE
[2,] FALSE  TRUE FALSE FALSE
[3,] FALSE FALSE FALSE FALSE
 > cbind(row(A)[sel],col(A)[sel])
      [,1] [,2]
[1,]    2    2
[2,]    1    4

Spencer Graves

John Janmaat wrote:
> Hello All,
> 
> Is there a fast way to find the index(row and column) of a point in a 
> matrix?
> 
> Thanks,
> 
> John.



More information about the R-help mailing list