Finding row index containing maximum value using R

后端 未结 3 1778
醉话见心
醉话见心 2020-11-30 23:28

Given the following matrix lets assume I want to find the maximum value in column two:

mat <- matrix(c(1:3,7:9,4:6), byrow = T, nc = 3)
mat
     [,1] [,2]         


        
3条回答
  •  攒了一身酷
    2020-12-01 00:12

    See ?order. You just need the last index (or first, in decreasing order), so this should do the trick:

    order(matrix[,2],decreasing=T)[1]
    

提交回复
热议问题