summarize {tidytable} | R Documentation |
Aggregate data using summary statistics
Description
Aggregate data using summary statistics such as mean or median. Can be calculated by group.
Usage
summarize(
.df,
...,
.by = NULL,
.sort = TRUE,
.groups = "drop_last",
.unpack = FALSE
)
summarise(
.df,
...,
.by = NULL,
.sort = TRUE,
.groups = "drop_last",
.unpack = FALSE
)
Arguments
.df |
A data.frame or data.table |
... |
Aggregations to perform |
.by |
Columns to group by.
|
.sort |
experimental: Default |
.groups |
Grouping structure of the result
|
.unpack |
experimental: Default |
Examples
df <- data.table(
a = 1:3,
b = 4:6,
c = c("a", "a", "b"),
d = c("a", "a", "b")
)
df %>%
summarize(avg_a = mean(a),
max_b = max(b),
.by = c)
df %>%
summarize(avg_a = mean(a),
.by = c(c, d))