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 transmute close together. Author: John Mount, Win-Vector LLC.

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

Arguments

d

data.frame

groupingVars

character vector of column names to group by.

...

list of dplyr::transmute() expressions.

arrangeTerms

character optional vector of quoted column expressions to arrange by.

env

environment to work in.

Value

d transmuteed by groups

Examples

group_transmute(datasets::mtcars, c("cyl", "gear"), group_mean_mpg = mean(mpg), group_mean_disp = mean(disp)) %.>% head(.)
#> # A tibble: 6 x 4 #> cyl gear group_mean_mpg group_mean_disp #> <dbl> <dbl> <dbl> <dbl> #> 1 6 4 19.8 164. #> 2 6 4 19.8 164. #> 3 4 4 26.9 103. #> 4 6 3 19.8 242. #> 5 8 3 15.0 358. #> 6 6 3 19.8 242.