Order of operations - summarize function

I am struggling to understand the purpose of the summarize function in summary statistics. Here is the question I am on:

Why does this code find the maximum value of the “price” column

most_expensive ← orders %>%
summarize(maximum = max(price, na.rm = TRUE))

instead of :

most_expensive ← orders %>%
max(summarize(price, na.rm = TRUE))

If summarize() turns the column into a vector, why is the maximum function performed on the column instead of the vector?

Thank you!
I’ve been trying to puzzle this out for days.

1 Like

summarize() as a function has more goals than to just list the max. It’s really to provide summary statistics: Summarise each group down to one row — summarise • dplyr


If i want to print just the max value and that’s all I care about

arr <- array(c(1, 2, 3, 4, 5, 6, 7, 8, 9), dim=c(3,3))
max_value <- max(arr)

is also perfectly valid (and will print 9).

There are multiple ways to get the same thing. Often in these lessons the goal is simply to expose you to some other construct you may not have run across.

Hey, thanks for your response!