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?