Trying to find row associated with max value in dataframe R

前端 未结 1 338
不思量自难忘°
不思量自难忘° 2021-01-27 22:45

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) 


        
相关标签:
1条回答
  • 2021-01-27 23:24

    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), ]
    
    0 讨论(0)
提交回复
热议问题