as.aggre | R Documentation |
aggre
Coerces an R object to an aggre
object, identifying
the object as one containing aggregated counts, person-years and other
information.
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, ...)
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 |
Returns a copy of x
with attributes set to those of an object of class
"aggre"
.
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)
Joonas Miettinen
Other aggregation functions:
aggre()
,
lexpand()
,
setaggre()
,
summary.aggre()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.