Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

summarize..html

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 = FALSE)

summarise.(.df, ..., .by = NULL, .sort = FALSE)

Arguments

.df

A data.frame or data.table

...

Aggregations to perform

.by

Columns to group by.

  • A single column can be passed with .by = d.

  • Multiple columns can be passed with .by = c(c, d)

  • tidyselect can be used:

    • Single predicate: .by = where(is.character)

    • Multiple predicates: .by = c(where(is.character), where(is.factor))

    • A combination of predicates and column names: .by = c(where(is.character), b)

.sort

experimental: Should the resulting data.table be sorted by the grouping columns?

Examples

test_df <- data.table(
  a = 1:3,
  b = 4:6,
  c = c("a","a","b"),
  d = c("a","a","b")
)

test_df %>%
  summarize.(avg_a = mean(a),
             max_b = max(b),
             .by = c)

test_df %>%
  summarize.(avg_a = mean(a),
             .by = c(c, d))

tidytable

Tidy Interface to 'data.table'

v0.6.1
MIT + file LICENSE
Authors
Mark Fairbanks [aut, cre], Abdessabour Moutik [ctb], Matt Carlson [ctb], Ivan Leung [ctb], Ross Kennedy [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.