给定以下矩阵,假设我想找到第二列中的最大值:
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
I know max(mat[,2])
将返回 8。如何返回行索引,在本例中为第二行?
See ?which.max
> which.max( matrix[,2] )
[1] 2
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)