Description Usage Arguments Details Value See Also Examples
Given a vector of age group labels, create a factor
that contains levels for all ages between break_min
and break_max
. The labels may contain an open age group
(ie an age group with no upper limit.)
Apart from the open age group, the age groups
produced by format_age_multi
all
have the same width, which is specified by width
,
and which defaults to 5.
1 2 3 4 5 6 7 | format_age_multi(
x,
width = 5,
break_min = 0,
break_max = 100,
open_last = TRUE
)
|
x |
A vector of age group labels. |
width |
The width in years of the age groups to be created. A positive integer. Defaults to 5. |
break_min |
An integer or |
break_max |
An integer or |
open_last |
Whether the final age group
has no upper limit. Defaults to |
Even when an age
group between break_min
and break_max
is not included in x
, format_age_multi
still creates a level for it.
If break_min
or break_max
is set to NULL
,
rather than to a specific value, then format_age_year
finds the narrowest range that accommodates the data.
All age groups in x
must fall within the intervals
determined by break_min
and width
,
except for age groups above break_max
.
If x
contains NA
, then the
levels of the factor created by format_age_multi
also contain NA
.
A factor with the same length as
x
.
Other functions for reformating age group labels are
format_age_year
format_age_lifetab
format_age_births
format_age_custom
format_age_quarter
format_age_month
date_to_age_year
creates
ages from dates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | format_age_multi(x = c(22, 11, 99, NA))
format_age_multi(x = c("10-14", "3", "100+", "77-79"))
format_age_multi(x = c("10-14", "3", "100+", "77-79"),
width = 10)
## age groups wider than the 'width' argument
## are allowed, provided they are above 'break_max'
format_age_multi(x = c("15", "30-39", "45-59"),
width = 10,
break_max = 40)
## allow 'break_min' and 'break_max' to be
## determined by the data
format_age_multi(x = c("22", "7", "30"),
break_min = NULL,
break_max = NULL)
## allow 'break_max' to be determined
## by the data, which includes an
## open age group
format_age_multi(x = c("17", "10+"),
break_max = NULL)
## oldest age group is closed
format_age_multi(x = c("10", "3", "77"),
open_last = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.