as_age_groups: Categorise continuous age into age groups

View source: R/helper_funs.R

as_age_groupsR Documentation

Categorise continuous age into age groups

Description

Categorise continuous age into age groups

Usage

as_age_groups(
  var,
  min = 0,
  max = 120,
  by = 10,
  grouping_method = c("user_defined", "ons_1", "ons_2", "nhs_survey")
)

Arguments

var

Name of variable or vector

min

Numeric, specifying the minimum age of the first age group. Age values lower than this will be returned as missing values (NA)

max

Numeric, specifying the upper end of the last age group

by

Numeric, increment of the age categories

grouping_method

String, specifying the method to be used for grouping age into categories. Details about the different methods are available here: "user_defined", "ons_1", "ons_2", "nhs_survey" ... TODO

Examples

# Example using a vector:
set.seed(123)
age <- sample(1:100, 100, replace = TRUE)
as_age_groups(age)

# Example using a data frame
tibble::tibble(age = sample(1:115, 100, replace = TRUE)) %>%
  dplyr::mutate(age_groups = as_age_groups(age, min = 10, max = 100))

CDU-data-science-team/nottshcMethods documentation built on March 19, 2023, 11:54 a.m.