I can find max values of rows, disp, hp
in mtcars dataset using sapply
function, which gives 472 335 respectively:
sapply(list(mtcars$disp,mtcars$hp), max, na.rm=TRUE)
Now I want cyl
for these values, i.e. cyl
of cars where maximum value of sapply(list(mtcars$disp,mtcars$hp),max,na.rm=TRUE)
is found.
Which function should I be using? I tried unsuccessfully with 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))