试图在数据帧 R 中找到与最大值关联的行 [英] Trying to find row associated with max value in dataframe R

查看:34
本文介绍了试图在数据帧 R 中找到与最大值关联的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说.我遇到了麻烦.例如,我有一个 2 列 (V1,V2) 数据框,其中有很多行,大约 300,000.我知道

Like the title says. I am having trouble. for example I have a 2 column (V1,V2) dataframe with lots of rows, around 300,000. I know that

max(df$V2) 

会给我第二列的最大值.现在我知道了我的最大值,我怎样才能获得与该值关联的整行.谢谢!

will give me the max value of that second column. Now that I know my max value, how can I get the entire row associated with that value. Thanks!

推荐答案

你必须写

df[which.max(df$V2), ]

如果不止一行包含最大值:

If more than one row contains the max:

i <- max(df$V2) 
df[which(df$V2 == i), ]

这篇关于试图在数据帧 R 中找到与最大值关联的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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