flip_to_start: Change the format of one-year period or cohort labels

Description Usage Arguments Details Value See Also Examples

View source: R/flip_to.R

Description

Change one-year period or cohort labels from using the calendar year at the start to using the calendar year at the end, or vice versa.

Usage

1
2
3
flip_to_start(x, month_start = "Jan")

flip_to_end(x, month_start = "Jan")

Arguments

x

A vector of period or cohort labels that are single-year or open on the left.

month_start

An element of month.name, or month.abb. Each period/cohort starts on the first day of this month.

Details

As discussed in date_to_period_year and date_to_cohort_year, single-year labels are ambiguous. The label "2020", for instance, could refer to many different sets of dates, depending on the starting month and on whether the 2020 refers to the calendar year at the start of the period or cohort, or the calendar year at the end.

Converting between calendar-year-at-end conventions and calendar-year-at-start conventions is error-prone. flip_to_end and flip_to_start try to make the process a little easer. The functions are used as follows

Current labels Desired labels Function to use
Use calendar year at start Use calendar year at end flip_to_end
Use calendar year at end Use calendar year at start flip_to_start

If month_start is "Jan" (so that the labels are the same under both conventions) flip_to_end and flip_to_start returns the original labels.

Value

A vector with the same length as x.

See Also

date_to_period_year, date_to_cohort_year, format_period_year, format_cohort_year

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## currently using calendar year at start of period
flip_to_end(x = c("2001", "2005"),
            month_start = "Jul")

## currently using calendar year at end of period
flip_to_end(x = c("2001", "2005"),
            month_start = "Jul")

## periods start in January, so changing labelling
## rule has no effect
flip_to_end(x = c("2001", "2005"),
            month_start = "Jan")

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