dtaggregate: Summary statistics with data subsets

View source: R/dtaggregate.R

dtaggregateR Documentation

Summary statistics with data subsets

Description

Calculation of summary statistics with data subsets using function data.table of package data.table. The function is generally faster than aggregate.

Usage


dtaggregate(formula, data, FUN = mean, ...)

Arguments

formula

A left and right-hand-sides formula defing the variable and the aggregation levels on which is calculated the statistic.

data

A data frame.

FUN

Function defining the statistic to compute (default to mean).

...

Eventual additional arguments to pass through FUN.

Value

A data.frame, see the examples.

Examples


dat <- data.frame(matrix(rnorm(2 * 100), ncol = 2))
names(dat) <- c("y1", "y2")
dat$typ1 <- sample(1:2, size = nrow(dat), TRUE)
dat$typ2 <- sample(1:3, size = nrow(dat), TRUE)

headm(dat)

dtaggregate(y1 ~ 1, data = dat)

dtaggregate(y1 ~ typ1 + typ2, data = dat)

dtaggregate(y1 ~ typ1 + typ2, data = dat, trim = .2)


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.