Description Usage Arguments Details Value Useful functions Backend variations Tidy data See Also Examples
Create one or more scalar variables summarizing the variables of an
existing tbl. Tbls with groups created by group_by()
will result in one
row in the output for each group. Tbls with no groups will result in one row.
1 2 3 |
.data |
A tbl. All main verbs are S3 generics and provide methods
for |
... |
Name-value pairs of summary functions. The name will be the
name of the variable in the result. The value should be an expression
that returns a single value like The arguments in |
summarise()
and summarize()
are synonyms.
An object of the same class as .data
. One grouping level will
be dropped.
Center: mean()
, median()
Spread: sd()
, IQR()
, mad()
Range: min()
, max()
, quantile()
Position: first()
, last()
, nth()
,
Count: n()
, n_distinct()
Logical: any()
, all()
Data frames are the only backend that supports creating a variable and using it in the same summary. See examples for more details.
When applied to a data frame, row names are silently dropped. To preserve,
convert to an explicit variable with tibble::rownames_to_column()
.
Other single table verbs: arrange
,
filter
, mutate
,
select
, slice
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # 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())
# 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()
# Note that with data frames, newly created summaries immediately
# overwrite existing variables
mtcars %>%
group_by(cyl) %>%
summarise(disp = mean(disp), sd = sd(disp))
# summarise() supports quasiquotation. You can unquote raw
# expressions or quosures:
var <- quo(mean(cyl))
summarise(mtcars, !!var)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.