as_age_groups | R Documentation |
Categorise continuous age into age groups
as_age_groups(
var,
min = 0,
max = 120,
by = 10,
grouping_method = c("user_defined", "ons_1", "ons_2", "nhs_survey")
)
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 |
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.