as.aggre: Coercion to Class 'aggre'

View source: R/aggregating.R

as.aggreR Documentation

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 class 'data.frame'
as.aggre(x, values = NULL, by = NULL, breaks = NULL, ...)

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

## Default S3 method:
as.aggre(x, ...)

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

Value

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

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(s)

Joonas Miettinen

See Also

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

Examples

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)


popEpi documentation built on Aug. 23, 2023, 5:08 p.m.