Assign single ages to age groups of equal and arbitrary width, and also optionally shifted.

calcAgeN(Age, N = 5, shiftdown = 0)

Arguments

Age

integer. Vector of single ages (lower bound).

N

integer. Desired width of resulting age groups.

shiftdown

integer. Move the grouping down by one or more single ages. Optional argument.

Value

An integer vector of length(Age) indicating the age group that each single age belongs to.

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 won't be N years wide. For example if shiftdown is 1, the first age group is 4-ages wide.

Examples

Age <- 0:100 calcAgeN(Age)
#> [1] 0 0 0 0 0 5 5 5 5 5 10 10 10 10 10 15 15 15 #> [19] 15 15 20 20 20 20 20 25 25 25 25 25 30 30 30 30 30 35 #> [37] 35 35 35 35 40 40 40 40 40 45 45 45 45 45 50 50 50 50 #> [55] 50 55 55 55 55 55 60 60 60 60 60 65 65 65 65 65 70 70 #> [73] 70 70 70 75 75 75 75 75 80 80 80 80 80 85 85 85 85 85 #> [91] 90 90 90 90 90 95 95 95 95 95 100
calcAgeN(Age, N = 4)
#> [1] 0 0 0 0 4 4 4 4 8 8 8 8 12 12 12 12 16 16 #> [19] 16 16 20 20 20 20 24 24 24 24 28 28 28 28 32 32 32 32 #> [37] 36 36 36 36 40 40 40 40 44 44 44 44 48 48 48 48 52 52 #> [55] 52 52 56 56 56 56 60 60 60 60 64 64 64 64 68 68 68 68 #> [73] 72 72 72 72 76 76 76 76 80 80 80 80 84 84 84 84 88 88 #> [91] 88 88 92 92 92 92 96 96 96 96 100
calcAgeN(Age, N = 3)
#> [1] 0 0 0 3 3 3 6 6 6 9 9 9 12 12 12 15 15 15 18 18 18 21 21 21 24 #> [26] 24 24 27 27 27 30 30 30 33 33 33 36 36 36 39 39 39 42 42 42 45 45 45 48 48 #> [51] 48 51 51 51 54 54 54 57 57 57 60 60 60 63 63 63 66 66 66 69 69 69 72 72 72 #> [76] 75 75 75 78 78 78 81 81 81 84 84 84 87 87 87 90 90 90 93 93 93 96 96 96 99 #> [101] 99
calcAgeN(Age, shiftdown = 1)
#> [1] 0 0 0 0 4 4 4 4 4 9 9 9 9 9 14 14 14 14 14 19 19 19 19 19 24 #> [26] 24 24 24 24 29 29 29 29 29 34 34 34 34 34 39 39 39 39 39 44 44 44 44 44 49 #> [51] 49 49 49 49 54 54 54 54 54 59 59 59 59 59 64 64 64 64 64 69 69 69 69 69 74 #> [76] 74 74 74 74 79 79 79 79 79 84 84 84 84 84 89 89 89 89 89 94 94 94 94 94 99 #> [101] 99
calcAgeN(Age, shiftdown = 2)
#> [1] 0 0 0 3 3 3 3 3 8 8 8 8 8 13 13 13 13 13 18 18 18 18 18 23 23 #> [26] 23 23 23 28 28 28 28 28 33 33 33 33 33 38 38 38 38 38 43 43 43 43 43 48 48 #> [51] 48 48 48 53 53 53 53 53 58 58 58 58 58 63 63 63 63 63 68 68 68 68 68 73 73 #> [76] 73 73 73 78 78 78 78 78 83 83 83 83 83 88 88 88 88 88 93 93 93 93 93 98 98 #> [101] 98
# can be used to group abridged into equal 5-year intervals AgeAbr <- c(0,1,5,10,15,20) calcAgeN(AgeAbr)
#> [1] 0 0 5 10 15 20