This can be useful to check constrained sums, or as an intermediate step for smoothing.

groupAges(
Value,
Age = 1:length(Value) - 1,
N = 5,
shiftdown = 0,
AgeN,
OAnew = max(Age)
)

## Arguments

Value numeric. Vector of single age counts. integer. Vector of lower bounds of single age groups. integer. The desired width of resulting age groups. Default 5. integer. Optionally shift age groupings down by single ages. Default 0. integer vector, otherwise calculated using calcAgeN(). Optional argument. integer. Value of lower bound of new open age group.

## Value

Vector of counts in N-year age groups.

## Details

If you shift the groupings, then the first age groups may have a negative lower bound (for example of -5). These counts would be discarded for the oscillatory version of Sprague smoothing, for example, but they are preserved in this function. The important thing to know is that if you shift the groups, the first and last groups will not be N years wide. For example if shiftdown is 1, the first age group is 4-ages wide. The ages themselves are not returned, but they are the name attribute of the output count vector. Note this will also correctly group abridged ages into equal 5-year age groups if the Age argument is explicitly given. OAnew (optional) must be less than or equal to max(Age) to have any effect.

## Examples

 Age <- 0:100
groupAges(pop1m_ind, N = 5)
#>        0        5       10       15       20       25       30       35
#> 52360652 57419164 51947630 42231074 37514223 34546587 29917765 27558300
#>       40       45       50       55       60       65       70       75
#> 22842245 18954561 16904890 10941747 11907237  6493630  5535950  2102284
#>       80       85       90       95      100
#>  2094961   601000   421930   134360    72373
groupAges(pop1m_ind, N = 5, shiftdown = 1)
#>        0        4        9       14       19       24       29       34
#> 40488149 61180144 51043772 46462353 37103293 37769292 29789068 28477079
#>       39       44       49       54       59       64       69       74
#> 22995247 19260609 16817385 11340613 11956304  6678264  5558252  2204548
#>       79       84       89       94       99
#>  2099864   630492   434099   120142    93594
groupAges(pop1m_ind, N = 5, shiftdown = 2)
#>        0        3        8       13       18       23       28       33
#> 28606305 58749766 57901419 41370149 44922109 34463405 35589397 26237746
#>       38       43       48       53       58       63       68       73
#> 26220797 17645765 18902154 10652783 12975223  6530648  5993071  2181397
#>       78       83       88       93       98
#>  2229770   638809   468914   110427   112509
groupAges(pop1m_ind, N = 5, shiftdown = 3)
#>        0        2        7       12       17       22       27       32
#> 17016196 60305957 54630220 49156093 40845737 40047411 33061379 30854134
#>       37       42       47       52       57       62       67       72
#> 24470101 20069309 17965797 12189059 12435565  7386079  5846470  2569058
#>       77       82       87       92       97
#>  2172557   755143   474788   133112   118398
groupAges(pop1m_ind, N = 5, shiftdown = 4)
#>        0        1        6       11       16       21       26       31
#>  9544406 55784596 59761861 46962015 45271071 39210273 36881374 29289697
#>       36       41       46       51       56       61       66       71
#> 26664183 19587214 18732143 11806528 13122301  7426622  6055763  2581755
#>       76       81       86       91       96
#>  2211834   835651   473762   167976   131538
groupAges(pop1m_ind, N = 5, OAnew = 80)
#>        0        5       10       15       20       25       30       35
#> 52360652 57419164 51947630 42231074 37514223 34546587 29917765 27558300
#>       40       45       50       55       60       65       70       75
#> 22842245 18954561 16904890 10941747 11907237  6493630  5535950  2102284
#>       80
#>  3324624