DTplyWithTotals: Compute on subgroups and subtotals using data.table instead...

Description Usage Arguments Examples

Description

This function takes a data table, subsets it according to the levels of one or more variables, and returns a data table containing the results computed on each subset, in addition to results computed on aggregate groups. See ddplyWithTotals for an alternative.

Usage

1
DTplyWithTotals(DT, variables, EXPR, nestedOnly = FALSE, grandTotal = FALSE)

Arguments

DT

data.table object to subset. Does not require a key, see data.table.

variables

Vector of character strings denoting variables to split on. Variables must be factors.

EXPR

An expression that indicates what to do with each subset of the data table

nestedOnly

Logical. Compute subtotals only for nested groups.

grandTotal

Logical. Compute the grand total.

Examples

1
2
3
4
mtcars2 <- data.table(mtcars, key = c("cyl", "gear"))
mtcars2[, cyl := as.factor(cyl)]
mtcars2[, gear := as.factor(gear)]
DTplyWithTotals(mtcars2, c("cyl", "gear"), list(mean = mean(wt)), grandTotal = TRUE)

sachsmc/rreporttools documentation built on May 29, 2019, 12:55 p.m.