Find value corresponding to maximum in other column [duplicate]
问题 This question already has answers here : Finding row index containing maximum value using R (3 answers) Closed 2 years ago . I have a data frame similar to as follows: x <- c(1, 2, 3, 4, 5) y <- c(1, 2, 3, 2, 1) df <- data.frame(x, y) I want to find the value of x when y is at its maximum. I know that I can find the max of y with this: max(df$y) But I don't know how to match it, and I think there's probably a better way. 回答1: Using dplyr : # install.packages(dplyr) library(dplyr) df %>%