Description Usage Arguments Details Value See Also Examples
View source: R/format_cohort.R
Given a vector of cohort labels, create a
factor
where the levels
contain a complete set of cohorts.
1 | format_cohort_month(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. |
The elements of x
must be month
labels, such as "2001 Jan"
or "2055 Sep"
, including
labels for cohorts that are open on the left,
such as "<2000 Mar"
or <"1960 Dec"
.
open_first
defaults to TRUE
if a value for break_min
is supplied,
or if any intervals in x
is open,
and to FALSE
otherwise.
If x
contains NA
, then the
levels of the factor created by format_cohort_month
also contain NA
.
A factor with the same length as
x
.
Other functions for reformating cohort labels are
format_cohort_year
format_cohort_multi
format_cohort_custom
format_cohort_quarter
date_to_cohort_month
creates
month cohorts from dates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | format_cohort_month(x = c("2003 Dec", "2005 Jan", NA, "2004 Sep"))
## 'open_first' defaults to TRUE, since 'x'
## contains an open interval
format_cohort_month(x = c("<2003 Dec", "2005 Jan", NA, "2004 Sep"))
## 'open_first' defaults to TRUE, since
## a value for 'break_min' is supplied
format_cohort_month(x = c("2003 Dec", "2005 Jan", NA, "2004 Sep"),
break_min = "2004 Jun")
## 'break_min' specified, and 'open_first' set to FALSE
format_cohort_month(x = c("2005 Jan", NA, "2004 May"),
break_min = "2004 Jan",
open_first = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.