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.
If open_first
is TRUE
, then the earliest
cohort has no lower limit.
1 | format_cohort_quarter(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. |
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.
Quarters are defined as follows:
Quarter | Start | End |
Q1 | 1 January | 31 March |
Q2 | 1 April | 30 June |
Q3 | 1 July | 30 September |
Q4 | 1 October | 31 December |
If x
contains NA
, then the
levels of the factor created by format_cohort_quarter
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_month
date_to_cohort_year
calculates
cohorts from dates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | format_cohort_quarter(x = c("2000 Q4", "2005 Q1", NA, "2004 Q3"))
## 'open_first' defaults to TRUE, since 'x'
## contains an open interval
format_cohort_quarter(x = c("<2000 Q4", "2005 Q1", NA, "2004 Q3"))
## 'open_first' defaults to TRUE, since
## a value for 'break_min' is supplied
format_cohort_quarter(x = c("2000 Q4", "2005 Q1", NA, "2004 Q3"),
break_min = "2004 Q1")
## 'break_min' specified, and 'open_first' set to FALSE
format_cohort_quarter(x = c("2005 Q1", NA, "2004 Q3"),
break_min = "2004 Q1",
open_first = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.