Learn R Programming

seplyr (version 1.0.4)

group_mutate: group_by and mutate as an atomic action.

Description

Group a data frame by the groupingVars and compute user summaries on this data frame (user summaries specified in ...). Enforces the good dplyr pipeline design principle of keeping group_by and mutate close together. Author: John Mount, Win-Vector LLC.

Usage

group_mutate(d, groupingVars, ..., arrangeTerms = NULL, env = parent.frame())

Arguments

d

data.frame

groupingVars

character vector of column names to group by.

...

list of dplyr::mutate() expressions.

arrangeTerms

character optional vector of quoted column expressions to arrange by.

env

environment to work in.

Value

d mutateed by groups

Examples

Run this code
# NOT RUN {

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

group_mutate(datasets::mtcars,
                    c("cyl", "gear"),
                    rank = dplyr::row_number(),
                    arrangeTerms = "-disp") %.>%
  head(.)

# }

Run the code above in your browser using DataLab