Guys, (use of max and which.max())
This only gives me the maximum value location in the whole matrix, but my intention is to run this for every column

i=1:4964
{which(M[,i]==max(M[,i]),arr.ind=TRUE)
}
;:output
row col
[1,] 266 3606

Is this what you are looking for?

set.seed(1)
MAT <- matrix(sample(1:16), nrow = 4)
MAT
#>      [,1] [,2] [,3] [,4]
#> [1,]    9    2   13    6
#> [2,]    4   14    5   15
#> [3,]    7   12   11   16
#> [4,]    1    3   10    8
apply(X = MAT, MARGIN = 2, FUN = which.max)
#> [1] 1 2 1 3

Created on 2020-11-13 by the reprex package (v0.3.0)

1 Like

OMG thanks it works
mate, I am new in r and not that good in programming,
and I can't believe someone replied to my query......Thanks a lot, this made my day, gives me the feeling I am not alone in this world😍

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.