Why I cant call the max function like ( mean etc) directly in a pipe?

hotel_bookings %>%

  • max(lead_time)
    Error in hotel_bookings %>% max(lead_time) : object 'lead_time' not found

hotel_bookings %>%

  • summarise(max(lead_time))

A tibble: 1 × 1


1 737

summarise takes responsibility for understanding the data.frame you provided, what columns are in it; when you call max() it gets the lead_time column for you and sends it to max() to calculate on. without summarise, you dont get that behaviour.
the code

hotel_bookings %>% max(lead_time)

is equivalent to
max(hotel_bookings,lead_time) and not max(hotel_bookings$lead_time)
you could do
hotel_bookings %>% pull(Sepal.Length) %>%max()

1 Like