Skip to contents

This function takes a dataset and a column containing age in integer form, and creates a new column with age group labels.

Usage

construct_leading_groups(
  data,
  age_col = "death2b",
  age_group_col = "age_grp_lead"
)

Arguments

data

A data frame containing the dataset.

age_col

The column name (as a string) containing age in integer form.

age_group_col

The new column name for the age group labels (default is "age_grp_lead").

Value

A data frame with the new age group column added.

Examples

data <- data.frame(death2b = c(3, 8, 45, 72))
data <- construct_leading_groups(data, age_col = 'death2b', age_group_col = "age_grp_lead")
print(data)
#>   death2b age_grp_lead
#> 1       3          0-4
#> 2       8         5-14
#> 3      45        15-69
#> 4      72          70+