[R] Index of item in matrix

white.denis@epamail.epa.gov white.denis at epamail.epa.gov
Thu Apr 3 04:15:24 CEST 2003


Try these:

which.col <- function (mat, x) (which(mat==x)-1) %/% nrow(mat) + 1
which.row <- function (mat, x) (which(mat==x)-1) %% nrow(mat) + 1

Knowing the R community, there may be already functions to do this.

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



More information about the R-help mailing list