getCounts: Aggregate person-month data into counts and totals by groups.

View source: R/getCounts.R

getCountsR Documentation

Aggregate person-month data into counts and totals by groups.

Description

Aggregate person-month data into counts and totals by groups.

Usage

getCounts(data, variables, by, ignore = NULL, addtotal = TRUE, drop = TRUE)

Arguments

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.

Value

data.frame of the ggregated counts.

Author(s)

Zehang Richard Li

Examples


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

 

bryandmartin/SUMMER documentation built on March 4, 2024, 4:56 p.m.