使用 R 查找包含最大值的行索引 [英] Finding row index containing maximum value using R
本文介绍了使用 R 查找包含最大值的行索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定以下矩阵,假设我想在第二列中找到最大值:
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]
[1,] 1 2 3
[2,] 7 8 9
[3,] 4 5 6
我知道 max(mat[,2])
会返回 8.我怎样才能返回行索引,在这种情况下是第二行?
I know max(mat[,2])
will return 8. How can I return the row index, in this case row two?
推荐答案
查看 ?which.max
> which.max( matrix[,2] )
[1] 2
这篇关于使用 R 查找包含最大值的行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文