Description Usage Arguments Details Value See Also Examples
View source: R/format_cohort.R
Given a vector of cohort labels, create a
factor
with a complete
set of cohorts. The labels
may include an "open" cohort with no
lower limit. Apart from the open cohort,
all cohorts have a width of one year.
1 | format_cohort_year(x, break_min = NULL, open_first = NULL)
|
x |
A vector of cohort labels. |
break_min |
An integer or |
open_first |
Whether the oldest cohort has no lower limit. |
x
must consist of labels for single-year
cohorts, such as "2001"
, or
open cohorts, such as "<2000"
.
x
must not contain labels for
multi-year cohorts such
as "2000-2005"
open_first
defaults to TRUE
if a value for break_min
is supplied,
or if any elements of x
are open,
and to FALSE
otherwise.
If x
has NA
s, then the
levels of the factor created by format_cohort_year
also contain NA
.
A factor with the same length as
x
.
Other functions for reformatting cohort labels are
format_cohort_multi
format_cohort_custom
format_cohort_quarter
format_cohort_month
date_to_cohort_year
creates
single-year cohorts 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 29 30 | ## the 'levels' contain all values from
## '2000' to '2005', even when these do not
## appear in the data
format_cohort_year(x = c(2000, 2005, NA, 2004))
## 'x' contains an open interval, so
## 'open_first' defaults to TRUE
format_cohort_year(x = c("<2000", "2005", NA, "2004"))
## specify 'break_min', which also makes
## 'open_first' default to TRUE
format_cohort_year(x = c(2000, 2005, NA, 2004),
break_min = 1998)
## set 'break_min' above minimum value of 'x'
format_cohort_year(x = c(2000, 2005, NA, 2004),
break_min = 2001)
## set 'open_first' to FALSE
format_cohort_year(x = c(2000, 2005, NA, 2004),
open_first = FALSE)
format_cohort_year(x = c(2000, 2005, NA, 2004),
break_min = 1998,
open_first = FALSE)
## if no value for 'break_min' is supplied, and one or
## more of the labels refers to an open cohort,
## then the levels start with the latest open cohort
format_cohort_year(x = c("2000", "2005", "<2002",
"2004", "<2001"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.