Learn R Programming

popEpi (version 0.4.12)

as.aggre: Coercion to Class aggre

Description

Coerces an R object to an aggre object, identifying the object as one containing aggregated counts, person-years and other information.

Usage

as.aggre(x, values = NULL, by = NULL, breaks = NULL, ...)

# S3 method for data.frame as.aggre(x, values = NULL, by = NULL, breaks = NULL, ...)

# S3 method for data.table as.aggre(x, values = NULL, by = NULL, breaks = NULL, ...)

# S3 method for default as.aggre(x, ...)

Value

Returns a copy of `x` with attributes set to those of an object of class `"aggre"`.

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.

...

arguments passed to or from methods

Methods (by class)

  • as.aggre(data.frame): Coerces a data.frame to an aggre object

  • as.aggre(data.table): Coerces a data.table to an aggre object

  • as.aggre(default): Default method for as.aggre (stops computations if no class-specific method found)

Author

Joonas Miettinen

See Also

Other aggregation functions: aggre(), lexpand(), setaggre(), summary.aggre()

Examples

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

df <- as.aggre(df, values = c("pyrs", "obs"), by = "sex")
dt <- as.aggre(dt, values = c("pyrs", "obs"), by = "sex")

class(df)
class(dt)

BL <- list(fot = 0:5)
df <- data.frame(df)
df <- as.aggre(df, values = c("pyrs", "obs"), by = "sex", breaks = BL)

Run the code above in your browser using DataLab