View source: R/create_age_groups.R
| create_age_groups | R Documentation |
create_age_groups() takes a numeric vector and assigns each age to the
appropriate age group.
create_age_groups(
x,
from = lifecycle::deprecated(),
to = lifecycle::deprecated(),
by = lifecycle::deprecated(),
as_factor = FALSE,
breaks = seq(0, 90, 5)
)
x |
a vector of numeric values |
from, to, by |
|
as_factor |
The default behaviour is to return a character vector. Use
|
breaks |
a numeric vector of cut points defining the age groups. The
default is |
The breaks vector defines the cut points for the age groups. The final
age group will capture all ages equal to or greater than the last value in
breaks, labelled as last+. If the cut points are not evenly spaced, the
labels will reflect the actual width of each group.
A character vector, where each element is the age group for the
corresponding element in x. If as_factor = TRUE, a factor
vector is returned instead.
age <- c(54, 7, 77, 1, 26, 101)
create_age_groups(age)
create_age_groups(age, breaks = seq(0, 80, 10))
# Non-uniform age groups
create_age_groups(age, breaks = c(0, 18, 45, 65, 90))
# Final group may start below the last break
create_age_groups(age, breaks = seq(0, 65, 10))
# To get the output as a factor:
create_age_groups(age, as_factor = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.