as.aggre {popEpi} | R 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 |
values |
a character string vector; the names of value variables |
by |
a character string vector; the names of variables by which
|
breaks |
a list of breaks, where each element is a breaks vector
as usually passed to e.g. |
... |
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 adata.frame
to anaggre
object -
as.aggre(data.table)
: Coerces adata.table
to anaggre
object -
as.aggre(default)
: Default method foras.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)