Learn R Programming

popEpi (version 0.4.12)

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 = NULL, breaks = NULL)

Value

Returns `x` invisibly after setting attributes to it without taking a copy. This function is called for its side effects.

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

breaks

a list of breaks, where each element is a breaks vector as usually passed to e.g. splitLexisDT. The list must be fully named, with the names corresponding to time scales at the aggregate level in your data. Every unique value in a time scale variable in data must also exist in the corresponding vector in the breaks list.

Author

Joonas Miettinen

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

Other aggregation functions: aggre(), as.aggre(), lexpand(), summary.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))
## without any breaks
setaggre(df, values = c("obs", "pyrs"), by = "sex")
df <- data.frame(df)
df$FUT <- 0:4
## with breaks list
setaggre(df, values = c("obs", "pyrs"), by = "sex", breaks = list(FUT = 0:5))

Run the code above in your browser using DataLab