max row and difference in answer

hi all, I'm new and just learning how to use rstudio
I'm trying to understand something
let say, when I want to know "what car has the highest horsepower (hp)? using mtcars dataset in rstudio
then I run

max(mtcars$hp)
 

[1] 335 comes out for the answer

then I do compare it to something a bit different
I run

library("dplyr")

and

mtcars%>%
  max(mtcars$hp)
  

[1] 472 comes out for the answer
why is that different?
and for "what car has the highest horsepower (hp)", how can I get maserati bora or the full detailed row of maserati bora as an answer? instead 335 as the highest hp on mtcars

thanks

The function max is not a tidyverse function so, to be honest, I am not sure what it actually does when you use it like that. You should use max inside a tidyverse function, such as filter:

mtcars %>% 
       filter(hp == max(hp))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.