format_cohort_month: Create consistent, complete one-month cohorts

Description Usage Arguments Details Value See Also Examples

View source: R/format_cohort.R

Description

Given a vector of cohort labels, create a factor where the levels contain a complete set of cohorts.

Usage

1
format_cohort_month(x, break_min = NULL, open_first = NULL)

Arguments

x

A vector of cohort labels.

break_min

An integer or NULL (the default). If an integer, it is the year in which the oldest cohort begins.

open_first

Whether the oldest cohort has no lower limit.

Details

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.

Value

A factor with the same length as x.

See Also

Other functions for reformating cohort labels are

date_to_cohort_month creates month cohorts from dates.

Examples

 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)

johnrbryant/demprep documentation built on Dec. 31, 2021, 11:58 a.m.