Hi everyone,
As a newbie, I am having troubles retrieving a particular detail from this data set. I wanted to see a car brand with the highest "Qsec" stat in the table and expected R to return something like "Merc 230 - 22.90". My line of code was "mtcars %>% max(mtcars$qsec)" and it returned "472" which was not what I wanted. And the first column doesn't have a name. What is the line of code to retrieve what I want? Thank you!
You can use use the base R function which.max() to get the index of the max value and then use this index to extract the corresponding car brand name:
index_max_qsec <- which.max(mtcars$qsec)
car_brand_max_qsec <- mtcars[index_max_qsec, c("vs","qsec","gear")]
car_brand_max_qsec
In addition to the base option shared by @TalhaAsif , here is a tidyverse approach.
library(dplyr)
mtcars %>% filter(qsec == max(qsec)) %>% select(qsec)
#> qsec
#> Merc 230 22.9
Thank you very much @TalhaAsif
Thank you very much @scottyd22