Skip to content
Back to formatted view

Raw Message

Message-ID: <3E8C6A07.5020807@pdf.com>
Date: 2003-04-03T17:06:15Z
From: Sundar Dorai-Raj
Subject: Index of item in matrix

Or more simply:

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

Though, the original post may need more clarification.

Sundar

Spencer Graves wrote:
> 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.
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>