View source: R/reaggregate_counts.R
reaggregate_counts | R Documentation |
reaggregate_counts()
converts counts over one interval range to another
with optional weighting by a known population.
reaggregate_counts(...)
## Default S3 method:
reaggregate_counts(
bounds,
counts,
new_bounds,
...,
population_bounds = NULL,
population_weights = NULL
)
... |
Further arguments passed to or from other methods. |
bounds |
The current boundaries in (strictly) increasing order. These correspond to the left hand side of the intervals (e.g. the closed side of [x, y). Double values are coerced to integer prior to categorisation. |
counts |
Vector of counts corresponding to the intervals defined by |
new_bounds |
The desired boundaries in (strictly) increasing order. |
population_bounds |
Interval boundaries for a known population weighting given by the
|
population_weights |
Population weightings corresponding to Used to weight the output across the desired intervals. If |
A data frame with 4 entries; interval
, lower_bound
, upper_bound
and a
corresponding count
.
# Reaggregating some data obtained from the 2021 UK census
head(pop_dat)
# Each row of the data is for the same region so we can drop some columns
# `age_category` and `value` columns
dat <- subset(pop_dat, select = c(age_category, value))
# Add the lower bounds to the data
dat <- transform(
dat,
lower_bound = as.integer(sub("\\[([0-9]+), .+)", "\\1", age_category))
)
# Now recategorise to the desired age intervals
with(
dat,
reaggregate_counts(
bounds = lower_bound,
counts = value,
new_bounds = c(0L, 1L, 5L, 15L, 25L, 45L, 65L)
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.