getCounts | R Documentation |
Aggregate person-month data into counts and totals by groups.
getCounts(data, variables, by, ignore = NULL, addtotal = TRUE, drop = TRUE)
data |
dataset in person-month format |
variables |
a character vector of the variables to aggregate |
by |
a character vector of columns that specifies which groups to aggregate by. |
ignore |
list of conditions not to impute 0. If left unspecified, any group levels not in the data will be imputed to have 0 counts. |
addtotal |
logical indicator of whether to add a column of group total counts. |
drop |
logical indicator of whether to drop all rows with total = 0. |
data.frame of the ggregated counts.
Zehang Richard Li
# a toy dataset with 4 time periods but one missing in data timelist <- factor(1:4) data = data.frame(died = c(0,0,0,1,1,0,0), area = c(rep(c("A", "B"), 3), "A"), time = timelist[c(1,1,2,3,3,3,3)]) data # without ignore argument, all levels will be imputed getCounts(data, variables = "died", by = c("area", "time")) # ignoring time = 4, the ignored level will not be imputed (but still in the output) getCounts(data, variables = "died", by = c("area", "time"), ignore = list("time"=c(4)) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.