Skip to content
Prev 79149 / 398502 Next

how to find indices of particular array elements

# create a 4x4 matrix with random values
smallmatrix = matrix(runif(16)*10, ncol = 4, nrow = 4)

# get the row and column number of the item in the
matrix with the highest value
which(smallmatrix == max(smallmatrix), arr.ind = 1)

HTH,

Martin

--- Jonathan Williams
<jonathan.williams at pharmacology.oxford.ac.uk> wrote:

            
__________________________________ 

Access over 1 million songs. Try it free.