【发布时间】:2017-11-05 10:21:45
【问题描述】:
我可以使用 sapply 函数在 mtcars 数据集中找到 rows, disp, hp 的最大值,分别给出 472 335:
sapply(list(mtcars$disp,mtcars$hp), max, na.rm=TRUE)
现在我想要cyl 获取这些值,即找到最大值为sapply(list(mtcars$disp,mtcars$hp),max,na.rm=TRUE) 的汽车的cyl。
我应该使用哪个功能?我尝试使用which,rownames,colnames 失败:
mtcars(which(sapply(list(mtcars$disp,mtcars$hp),max,na.rm=TRUE)))
rownames(which(sapply(list(mtcars$disp,mtcars$hp),max,na.rm=TRUE))))
mtcars$cyl(sapply(list(mtcars$disp,mtcars$hp),max,na.rm=TRUE))
【问题讨论】: