[R] Index of item in matrix

Torsten Hothorn Torsten.Hothorn at rzmail.uni-erlangen.de
Thu Apr 3 09:17:27 CEST 2003


> Hello All,
>
> Is there a fast way to find the index(row and column) of a point in a
> matrix?
>

R> a <- matrix(1:25, ncol=5)
R> which(a == 2, arr.ind=TRUE)
     row col
[1,]   2   1
R> a
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    6   11   16   21
[2,]    2    7   12   17   22
[3,]    3    8   13   18   23
[4,]    4    9   14   19   24
[5,]    5   10   15   20   25

best,

Torsten

> Thanks,
>
> John.
> --
> --------------------------------------------------------------------------
> Dr. John Janmaat
> Department of Economics, Acadia University, Wolfville, NS, B4P 2R6
> E-mail: jjanmaat at acadiau.ca        Web: http://ace.acadiau.ca/~jjanmaat
> Tel: 902-585-1461		   Fax: 902-585-1070
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
>



More information about the R-help mailing list