Description Usage Arguments Details Value See Also Examples
Given a vector of age group labels, create a factor
that contains levels for all age groups, as
defined by the breaks
argument. The labels may include an
open age group, ie an age group with no upper limit.
1 | format_age_custom(x, breaks = NULL, open_last = TRUE)
|
x |
A vector of age group labels. |
breaks |
A vector of strictly increasing integer values. |
open_last |
Whether the final age group
has no upper limit. Defaults to |
format_age_custom
is the most flexible
of the format_age
functions
in that the age groups can have any combination of widths.
breaks
is used to specify the points at which
each age group starts and finishes, and open_last
is used to specify whether the final age group
has an upper limit. If breaks
has
length n
, then the
final age group is defined as follows:
open_last | Final age group |
TRUE | [breaks[n] , Inf ) |
FALSE | [breaks[n-1] , breaks[n] )
|
If x
contains NA
, then the
levels of the factor created by format_age_custom
also contain NA
.
A factor with length equal to x
.
Other functions for creating age groups are
format_age_year
format_age_multi
format_age_lifetab
format_age_births
format_age_quarter
format_age_month
date_to_age_year
calculates
ages from dates.
1 2 3 4 5 6 7 | format_age_custom(x = c(22, 11, 85),
breaks = c(0, 15, 45, 70))
format_age_custom(x = c("90+", "19-40", "22", NA),
breaks = c(0, 15, 60))
format_age_custom(x = c("50-59", "19-40", "31"),
breaks = c(15, 45, 60),
open_last = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.