Learn R Programming

popEpi (version 0.3.1)

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 = setdiff(names(x), values), ...)
"as.aggre"(x, values = NULL, by = setdiff(names(x), values), ...)
"as.aggre"(x, values = NULL, by = setdiff(names(x), values), ...)
"as.aggre"(x, ...)

Arguments

x
an R object to coerce to aggre; must be 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
...
arguments passed to or from methods

Methods (by class)

  • data.frame: Coerces a data.frame to an aggre object
  • data.table: Coerces a data.table to an aggre object
  • default: Default method for as.aggre (stops computations if no class-specific method found)

See Also

setaggre for modifying in place

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

Run the code above in your browser using DataLab