2

We all know that we can compute any summary that operates on vectors and returns a single value in R base. I want to ask that why I don't get an error when I attempt to use quantile which returns more than one value function inside of summarize?

heights %>%
    filter(sex == "Male") %>%
    summarize(range = quantile(height, c(0, 0.5, 1)))

result is not an error:

     range
1 50.00000
2 69.00000
3 82.67717
Ric S
  • 9,073
  • 3
  • 25
  • 51
sociolog
  • 83
  • 1
  • 8
  • 1
    `dplyr 1.0.0` permits `summarize()` to return vectors of length > 1 see https://www.tidyverse.org/blog/2020/03/dplyr-1-0-0-summarise/. – Ritchie Sacramento Jun 25 '20 at 12:42
  • 1
    From the examples of `summarise`'s [documentation](https://dplyr.tidyverse.org/reference/summarise.html#examples), `dplyr 1.0.0` allows to summarise to more than one value – Ric S Jun 25 '20 at 12:42
  • I got it, thank you ! – sociolog Jun 25 '20 at 12:44

1 Answers1

1

Just making my comment and @27ϕ9's an answer.

As of dplyr version 1.0.0, summarise allows to return outputs containing more than one value.

Example:

mtcars %>%
  group_by(cyl) %>%
  summarise(qs = quantile(disp, c(0.25, 0.75)), prob = c(0.25, 0.75))

# A tibble: 6 x 3
# Groups:   cyl [3]
#     cyl    qs  prob
#   <dbl> <dbl> <dbl>
# 1     4  78.8  0.25
# 2     4 121.   0.75
# 3     6 160    0.25
# 4     6 196.   0.75
# 5     8 302.   0.25
# 6     8 390    0.75

See the documentation for more examples.

Ric S
  • 9,073
  • 3
  • 25
  • 51