问题
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