fiscal_year: Convert dates to fiscal years

Description Usage Arguments Value Examples

Description

Convert a vector of dates or monthly data to the enclosing fiscal year. There are options to change the start of the fiscal year and choose from either numeric or label output.

Usage

1
fiscal_year(x, start = 4, label = FALSE)

Arguments

x

A date vector or a vector of class "yearmon" from the zoo package.

start

An integer between 1 and 12 representing the month on which the fiscal begins. The default gives April.

label

Should labels be returned instead of numeric years? If label = TRUE then the out will be a character vector of labels for the appropriate fiscal years, e.g. "2017/18".

Value

By default, a numeric vector of fiscal years or, if label = TRUE, a character vector of fiscal years.

Examples

1
2
3
4
5
6
x <- seq.Date(as.Date("2012-01-01"), as.Date("2017-01-01"), by = "month")

fiscal_year(x)             # April is the default starting month
fiscal_year(x, start = 7)  # But this can be changed

fiscal_year(x, label = TRUE)  # Label output may be attractive when publishing results

liam-c-smith/secretsauce documentation built on May 16, 2019, 7:16 p.m.