nettle_fy: Define Fiscal Years

Description Usage Arguments Details Examples

View source: R/Fiscal_Years.R

Description

Return the year (fiscal or calendar) and quarter in which the date appears.

Usage

1
2
nettle_fy(x, firstMonth = 10, fy.prefix = "FY", quarter.prefix = "Q",
  sep = "-", level.range = c(min(x), max(x)))

Arguments

x

vector of type Date.

firstMonth

the month corresponding to the first month of the fiscal year (default is October) Setting firstMonth=1 is equivalent calendar years.

fy.prefix

the character string to paste before the year.

quarter.prefix

the character string to paste before the quarter.

sep

the separater between the year and quarter.

level.range

the range to use for defining the levels in the returned factor.

Details

This function will cut the given date vector into quarters (i.e. three month increments) and return an ordered factor with levels defined to be the quarters between the minimum and maximum dates in the given vector. The levels, by default, will be formated as FY2013-Q1, however the FY and Q can be changed using the fy.prefix and quarter.prefix parameters, respectively.

Original Script can be found at jbryer's Gist site: https://gist.github.com/jbryer/5412193

Here's how to call the function from there directly: gistfile <- "https://gist.github.com/jbryer/5412193" library(devtools) source_gist(gistfile)

The original function has been modified for Federal Calendar (October 1 begins FY of following calendar year)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
dates <- as.Date(c('2013-04-03','2012-03-30','2011-10-31',
	                   '2011-04-14','2010-04-22','2004-10-04',
	                   '2000-02-29','1997-12-05','1997-04-23',
	                   '1997-04-01'))
	nettle_fy(dates)
	nettle_fydates, firstMonth=1)
	nettle_fy(dates, 1, '', '', '')
	## Not run: 
	nettle_fy(dates, level.range=as.Date(c('2010-01-01','2013-01-01')))
	
## End(Not run)

ctmann/nettles.toolbox documentation built on May 14, 2019, 12:29 p.m.