【发布时间】:2020-10-17 02:35:13
【问题描述】:
假设以下数据框:
df<-data.frame(a=c("red", "blue", "yellow", "orange"), b=c(1,4,5,7), c=c(2,7,4,1), d=c(4,3,8,1))
使用dplyr,我想在b,c和d列中获取与每个最大值和最小值对应的a元素:
对于最大值,这将返回 orange, blue and yellow
我能够获取 max 值的索引,但无法从列 a 获取值:
df %>% summarise(across(-c(1), ~which.max(.x)))
【问题讨论】: