使用R查找包含最大值的行索引 [英] Finding row index containing maximum value using R

查看:190
本文介绍了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆