Learn R Programming

popEpi (version 0.3.1)

setaggre: Set 'aggre' attributes to an object by modifying in place

Description

Coerces an R object to an aggre object, identifying the object as one containing aggregated counts, person-years and other information. setaggre modifies in place without taking any copies. Retains all other attributes.

Usage

setaggre(x, values = NULL, by = setdiff(names(x), values))

Arguments

x
a data.frame or data.table
values
a character string vector; the names of value variables
by
a character string vector; the names of variables by which values have been tabulated

Details

setaggre sets x to the aggre class in place without taking a copy as e.g. as.data.frame.XXX functions do; see e.g. setDT.

See Also

as.aggre

Examples

Run this code
df <- data.frame(sex = rep(c("male", "female"), each = 5), 
                 obs = rpois(10, rep(7,5, each=5)), 
                 pyrs = rpois(10, lambda = 10000))
setaggre(df, values = c("obs", "pyrs"), by = "sex")

Run the code above in your browser using DataLab