aggregate_age_counts {ageutils} | R Documentation |
Aggregate counts across ages
Description
aggregate_age_counts()
provides aggregation of counts across ages (in
years). It is similar to a cut()
and tapply()
pattern but optimised for
speed over flexibility. It takes a specified set of breaks representing the
left hand limits of a closed open interval, i.e [x, y), and returns the
corresponding interval and upper bounds. The resulting intervals span from
the minimum break through to the maximum age. Missing values are grouped as
NA.
Usage
aggregate_age_counts(counts, ages = seq_along(counts) - 1L, breaks)
Arguments
counts |
Vector of counts to be aggregated. |
ages |
Vector of age in years. Double values are coerced to integer prior to categorisation / aggregation. For No (non-missing) age can be less than the minimum break. |
breaks |
1 or more cut points in increasing (strictly) order. These correspond to the left hand side of the desired intervals (e.g. the closed side of [x, y). Double values are coerced to integer prior to categorisation. |
Value
A data frame with 4 entries; interval
, lower_bound
, upper_bound
and an
associated count
.
Examples
# default ages generated if only counts provided (here ages will be 0:64)
aggregate_age_counts(counts = 1:65, breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L))
# NA ages are handled with their own grouping
ages <- 1:65
ages[1:44] <- NA
aggregate_age_counts(
counts = 1:65,
ages = ages,
breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L)
)