agg: Aggregate Measures By Dimensions

View source: R/agg.R

aggR Documentation

Aggregate Measures By Dimensions

Description

This function is great for getting rollups across various dimensions

Usage

agg(.data, .dims = NULL, .all_dims, ..., .append = TRUE)

Arguments

.data

A data frame

.dims

Character vector of column names that represent the data frames dimensions to be grouped by and summarised with the formulas in

.all_dims

Character vector of column names that represent the data frames entire set of dimensions. All other columns will be ignored unless referenced in ...

...

Named expressions passed to dplyr::summarise(). These formulas are also applied at the rowwise level in a dplyr::mutate call to .data

.append

Logical, whether or not to append the aggregated data to .data with "TOTAL" rows

Value

Data frame

Examples

library(dplyr)
agger <- purrr::partial(
  agg,
  conc = mean(conc, na.rm = TRUE),
  uptake = mean(uptake, na.rm = TRUE),
  .all_dims = c("Plant", "Type", "Treatment")
)
tibble::tibble(datasets::CO2) %>%
  agger(c("Plant", "Type")) %>%
  agger("Treatment")


EricLamphere/ezxfig documentation built on Jan. 29, 2023, 1:44 a.m.