Description Usage Arguments Details Value See Also Examples
View source: R/format_period.R
Given a vector of period labels, create a
factor  containing
levels for the earliest and latest periods
in x, and for all periods in between.
All periods have the same width,
which is controlled by the width argument.
1 2 3 4 5 6 7  | format_period_multi(
  x,
  width = 5,
  origin = 2000,
  month_start = "Jan",
  label_year_start = TRUE
)
 | 
x | 
 A vector of period labels.  | 
width | 
 The width, in whole years, of the periods to be created. Defaults to 5.  | 
origin | 
 An integer. Defaults to 2000.  | 
month_start | 
 An element of   | 
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   | 
The elements of x are typically multi-year
labels such as "1950-1960" or
"2020-2025" or single-year
labels such as "2000" or "2025".
x cannot contain open intervals
such as "<2020".
As discussed in date_to_period_year,
single-year labels such as "2000" are ambiguous.
Correctly aligning single-year and multi-year periods
requires knowing which month the single-year periods start on,
which is controlled by the month_start
argument, and whether single-year periods
are labelled according 
to the calendar year at the start or end of the period,
which is controlled by the label_year_start
argument.
The location of the periods can be shifted
by using different values for origin.
If x contains NA, then the
levels of the factor created by format_period_multi
also contain NA.
A factor with the same length as
x.
Other functions for reformating period labels are
format_period_year
format_period_custom
format_period_quarter
format_period_month
date_to_period_year creates
periods from dates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23  | format_period_multi(x = c("2000-2001", "2005-2010", NA, "1996-1998"))
## use non-default value for 'width'
format_period_multi(x = c("2000-2001", "2005-2010", NA, "1996-1998"),
                    width = 10)
## use non-default value for 'origin' to shift periods
format_period_multi(x = c("2000-2001", "2005-2010", NA, "1996-1998"),
                    width = 10,
                    origin = 2001)
## Labels include single-year periods. Use default assumption
## that single-year periods start in January and/or
## are labelled by the calendar year at the start of
## the period
format_period_multi(x = c("2000-2001", "2005", NA, "1996-1998"))
## Change to assumption that single-year periods are
## start in July, and are labelled by the calendar
## year at the end of the period
format_period_multi(x = c("2000-2001", "2005", NA, "1996-1998"),
                    month_start = "Jul",
                    label_year_start = FALSE)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.