Skip to contents

Collapse upper ages into a single age group. Counts are summed while rates are recomputed where possible.

Usage

collapse_ages(.data, max_age = 100)

Arguments

.data

A vital object including an age variable

max_age

Maximum age to include in the collapsed age group.

Value

A vital object with the same variables as .data, but with the upper ages collapsed into a single age group.

Details

If the object includes deaths, population and mortality rates, then deaths and population are summed and mortality rates are recomputed as deaths/population. But if the object contains mortality rates but not deaths and population, then the last rate remains unchanged (and a warning is generated).

Author

Rob J Hyndman

Examples

aus_mortality |>
 dplyr::filter(State == "Victoria", Sex == "female") |>
 collapse_ages(max_age = 85)
#> # A vital: 10,320 x 8 [1Y]
#> # Key:     Age x (Sex, State, Code) [86 x 1]
#>     Year   Age Sex    State    Code  Mortality Exposure Deaths
#>    <int> <int> <chr>  <chr>    <chr>     <dbl>    <dbl>  <dbl>
#>  1  1901     0 female Victoria VIC     0.100      13993   1405
#>  2  1901     1 female Victoria VIC     0.0235     13079    308
#>  3  1901     2 female Victoria VIC     0.00806    12409    100
#>  4  1901     3 female Victoria VIC     0.00472    12931     61
#>  5  1901     4 female Victoria VIC     0.00370    12986     48
#>  6  1901     5 female Victoria VIC     0.00324    13589     44
#>  7  1901     6 female Victoria VIC     0.00310    13872     43
#>  8  1901     7 female Victoria VIC     0.00284    14077     40
#>  9  1901     8 female Victoria VIC     0.00261    14198     37
#> 10  1901     9 female Victoria VIC     0.00225    14694     33
#> # ℹ 10,310 more rows