| summarise {poorman} | R Documentation |
Reduce multiple values down to a single value
Description
Create one or more scalar variables summarising the variables of an existing data.frame. Grouped data.frames will
result in one row in the output for each group.
Usage
summarise(.data, ..., .groups = NULL)
summarize(.data, ..., .groups = NULL)
Arguments
.data |
A |
... |
Name-value pairs of summary functions. The name will be the name of the variable in the result. |
.groups |
When
In addition, a message informs you of that choice, unless the result is ungrouped, the option
The value can be:
|
Details
summarise() and summarize() are synonyms.
Examples
# A summary applied to ungrouped tbl returns a single row
mtcars %>%
summarise(mean = mean(disp), n = n())
# Usually, you'll want to group first
mtcars %>%
group_by(cyl) %>%
summarise(mean = mean(disp), n = n())
# You can summarise to more than one value:
mtcars %>%
group_by(cyl) %>%
summarise(qs = quantile(disp, c(0.25, 0.75)), prob = c(0.25, 0.75))
# You use a data frame to create multiple columns so you can wrap
# this up into a function:
my_quantile <- function(x, probs) {
data.frame(x = quantile(x, probs), probs = probs)
}
mtcars %>%
group_by(cyl) %>%
summarise(my_quantile(disp, c(0.25, 0.75)))
# Each summary call removes one grouping level (since that group
# is now just a single row)
mtcars %>%
group_by(cyl, vs) %>%
summarise(cyl_n = n()) %>%
group_vars()