Learn R Programming

seplyr (version 1.0.4)

add_group_summaries: Simulate the group_by/mutate pattern with an explicit summarize and join.

Description

Group a data frame by the groupingVars and compute user summaries on this data frame (user summaries specified in ...), then join these new columns back into the original data and return to the user. Author: John Mount, Win-Vector LLC.

Usage

add_group_summaries(d, groupingVars, ..., arrangeTerms = NULL)

Arguments

d

data.frame

groupingVars

character vector of column names to group by.

...

list of dplyr::mutate() expressions.

arrangeTerms

character optional vector of column expressions to arrange by.

Value

d with grouped summaries added as extra columns

Examples

Run this code
# NOT RUN {

add_group_summaries(datasets::mtcars,
                    c("cyl", "gear"),
                    group_mean_mpg = mean(mpg),
                    group_mean_disp = mean(disp)) %.>%
  head(.)

# }

Run the code above in your browser using DataLab