This method splits an age interval from min_val
to max_val
into intervals of size step
.
If the method finds ages greater or equal than max_val
it assigns the string ">max_val"
.
By default min_val
is set to 0, however it can be assigned by
convenience. If the method finds ages lower or equal
than min_val
it assigns the string "<min_val-1"
.
The function warns when (max_val - min_val) is not an integer multiple of
step. In that case the last interval is truncated to the upper value
closest to max_val for which (closest_upper - min_val) is multiple of step.
Value
Column of type factor
with the same length as the number of rows
in data_set
, with levels corresponding to age bins between min_val
and
max_val
. Ages above max_val
are represented as >max_val
.
Examples
# load data provided with the package
data(cohortdata)
# assign age groups as a column of the `data.frame`
cohortdata$age_group <- get_age_group(
data_set = cohortdata,
col_age = "age",
max_val = 80,
step = 10
)
# view the `data.frame` with new column
head(cohortdata)
#> id sex age death_date death_other_causes vaccine_date_1 vaccine_date_2
#> 1 afade1b2 F 37 <NA> <NA> <NA> <NA>
#> 2 556c8c76 M 19 <NA> <NA> <NA> <NA>
#> 3 04edf85a M 50 <NA> <NA> <NA> <NA>
#> 4 7e51a18e F 8 <NA> <NA> <NA> <NA>
#> 5 c5a83f56 M 66 <NA> <NA> <NA> <NA>
#> 6 7f675ec3 M 29 <NA> <NA> 2044-04-09 2044-04-30
#> vaccine_1 vaccine_2 age_group
#> 1 <NA> <NA> 30-39
#> 2 <NA> <NA> 10-19
#> 3 <NA> <NA> 50-59
#> 4 <NA> <NA> 0-9
#> 5 <NA> <NA> 60-69
#> 6 BRAND1 BRAND1 20-29