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

max(lead_time)

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

This topic was automatically closed 42 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.