Learn R Programming

popEpi (version 0.2.1)

expr.by.cj: Tabulate counts and other functions with multiple factors into a long-format table

Description

Like ltable except faster and unrobust. For advanced users.

Usage

expr.by.cj(data, by.vars = "sex", expr = list(obs = .N), subset = NULL,
  .SDcols, ...)

Arguments

data
a data.table
by.vars
a character string vector specifying the names of variables, by the combinations of which to evaluate the given expr
expr
an arbitrary expression utilizing any available function on any variable available in the data
subset
a logical condition; data is limited accordingly before evaluating expr
.SDcols
advanced; passed to inside the data.table's brackets DT[, , ...]; see data.table
...
advanced; other arguments passed to inside the data.table's brackets DT[, , ...]; see data.table

Examples

Run this code
sr <- copy(sire)
sr$agegroup <- cut(sr$dg_age, breaks=5)
## counts by default
expr.by.cj(sr, "agegroup")

## any arbitrary expression can be given
expr.by.cj(sr, "agegroup", list(mage = mean(dg_age)))
expr.by.cj(sr, "agegroup", list(mage = mean(dg_age), vage = var(dg_age)))

## only uses levels of by.vars present in data
expr.by.cj(sr, "agegroup", list(mage = mean(dg_age), vage = var(dg_age)),
           subset = dg_age < 70)

Run the code above in your browser using DataLab