>-----Original Message-----
>From: [EMAIL PROTECTED] 
>[mailto:[EMAIL PROTECTED] On Behalf Of John Janmaat
>Sent: Wednesday, April 02, 2003 12:39 PM
>To: [EMAIL PROTECTED]
>Subject: [R] Index of item in matrix
>
>
>Hello All,
>
>Is there a fast way to find the index(row and column) of a point in a

>matrix?
>
>Thanks,
>
>John.

Look at ?which.

Specifically the form: which(x, arr.ind = TRUE)

> m <- matrix(1:12,3,4) 
> m
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> which(m == 9, arr.ind = TRUE)
     row col
[1,]   3   3
> m[3,3]
[1] 9


HTH,

Marc Schwartz

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to