format_period_custom: Create consistent, complete customised periods

Description Usage Arguments Details Value See Also Examples

View source: R/format_period.R

Description

Given a vector of period labels, create a factor that contains levels for all periods defined by breaks. format_period_custom is the most flexible of the format_period functions in that the periods can have any combination of widths.

Usage

1
format_period_custom(x, breaks, month_start = "Jan", label_year_start = TRUE)

Arguments

x

A vector of period labels.

breaks

A vector of strictly increasing integer values.

month_start

An element of month.name, or month.abb. Periods start on the first day of this month.

label_year_start

Logical. Whether to label a period by the calendar year at the beginning of the period or the calendar year at the end. Defaults to TRUE.

Details

The elements of x can be single-year labels such as "2000" and "1975", multi-year labels such as "1950-1960" and "2020-2025", or a mixture of the two. x cannot contain open intervals such as "<2020".

If x contains NA, then the levels of the factor created by format_period_custom also contain NA.

Value

A factor with the same length as x.

See Also

Other functions for reformating period labels are

date_to_period_year creates periods from dates.

Examples

1
2
3
4
5
format_period_custom(x = c("2000-2001", "2004", "2005-2010", "1996-1998"),
                     breaks = c(1990, 2000, 2020))

format_period_custom(x = c("2000-2001", "2004", "2005-2010", "1996-1998"),
                     breaks = c(1995, 2005, 2010, 2020))

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