Skip to contents

reaggregate_interval_counts() converts counts over one interval range to another. It first splits counts of a given age interval in to counts for individual years based on a given weighting. These are then aggregated to the desired breaks. Functionally this is equivalent to, but more efficient than, a call to split_interval_counts() followed by aggregate_age_counts().

Usage

reaggregate_interval_counts(
  lower_bounds,
  upper_bounds,
  counts,
  breaks,
  max_upper = 100L,
  weights = NULL
)

Arguments

lower_bounds, upper_bounds

[integerish].

A pair of vectors representing the bounds of the intervals.

lower_bounds must be strictly less than upper_bounds and greater than or equal to zero.

Missing (NA) bounds are not permitted.

Double vectors will be coerced to integer.

counts

[numeric].

Vector of counts to be aggregated.

breaks

[numeric].

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.

max_upper

[integerish]

Represents the maximum upper bounds permitted upon splitting the data.

Any upper bound greater than this will be replaced with this value prior to splitting.

Double vectors will be coerced to integer.

weights

[numeric]

Population weightings to apply for individual years.

If NULL (default) counts will be split evenly based on interval size.

If specified, must be of length max_upper and represent weights in the range 0:(max_upper - 1).

Value

A data frame with 4 entries; interval, lower_bound, upper_bound and an associated count.

Examples


reaggregate_interval_counts(
    lower_bounds = c(0, 5, 10),
    upper_bounds = c(5, 10, 20),
    counts = c(5, 10, 30),
    breaks = c(0L, 1L, 5L, 15L, 25L, 45L, 65L)
)
#>    interval lower_bound upper_bound count
#> 1    [0, 1)           0           1     1
#> 2    [1, 5)           1           5     4
#> 3   [5, 15)           5          15    25
#> 4  [15, 25)          15          25    15
#> 5  [25, 45)          25          45     0
#> 6  [45, 65)          45          65     0
#> 7 [65, Inf)          65         Inf     0