Here is a function that will find the row and column indices of a matrix that
are associated with a vector index.
Usage
GetRowCol(Index, dim1, dim2)
Arguments
Index
an integer vector index
dim1
integer row dimension of the matrix from which the row and column
indices are to be extracted
dim2
integer column dimension of the matrix from which the row and
column indices are to be extracted
Value
a numeric vector of length two with two integers indicating row and
column respectively
Details
Often when applying functions like the R function which.max(matrix) to a
matrix, a vector index is returned when the coder would prefer to have a row
and column indices. This function converts the vector index to row and column
indices.
The function assumes that the elements of the matrix are filled by column
(byrow = FALSE), which is the default R matrix behaviour.