Trying to find row associated with max value in dataframe R

我的梦境 提交于 2021-02-05 11:09:47

问题


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!


回答1:


You have to write

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

If more than one row contains the max:

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


来源:https://stackoverflow.com/questions/36802736/trying-to-find-row-associated-with-max-value-in-dataframe-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!