Skip to content

Index of item in matrix

3 messages · White.Denis@epamail.epa.gov, Peter Dalgaard, John Janmaat

#
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.
#
white.denis at epamail.epa.gov writes:
There is. Take another look at ?which.
#
Hello All,

Thanks,

John.
Peter Dalgaard BSA wrote: