-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote quarter accessor, which returns a date's quarter as a number.
- Loading branch information
1 parent
9c0c451
commit 453d056
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,4 @@ Collate: | |
'guess.r' | ||
'stamp.r' | ||
'ops-%m+%.r' | ||
'accessors-quarter.r' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' @include accessors-month.r | ||
NULL | ||
|
||
#' Get the fiscal quarter of a date-time. | ||
#' | ||
#' Fiscal quarters are a way of dividing the year into fourths. The first quarter (Q1) | ||
#' comprises January, February and March; the second quarter (Q2) comprises April, May, | ||
#' June; the third quarter (Q3) comprises July, August, September; the fourth quarter (Q4) | ||
#' October, November, December. | ||
#' | ||
#' @param x a date-time object of class POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo, | ||
#' zooreg, timeDate, xts, its, ti, jul, timeSeries, fts or anything else that can be converted | ||
#' with as.POSIXlt | ||
#' @keywords utilities manip chron methods | ||
#' @return numeric the fiscal quarter that the date-time occurs in | ||
#' @examples | ||
#' x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31")) | ||
#' # 1 2 3 4 | ||
#' @export | ||
quarter <- function(x) { | ||
m <- month(x) | ||
quarters <- c("1" = 1, | ||
"2" = 1, | ||
"3" = 1, | ||
"4" = 2, | ||
"5" = 2, | ||
"6" = 2, | ||
"7" = 3, | ||
"8" = 3, | ||
"9" = 3, | ||
"10" = 4, | ||
"11" = 4, | ||
"12" = 4) | ||
unname(quarters[m]) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
\name{quarter} | ||
\alias{quarter} | ||
\title{Get the fiscal quarter of a date-time.} | ||
\usage{ | ||
quarter(x) | ||
} | ||
\arguments{ | ||
\item{x}{a date-time object of class POSIXct, POSIXlt, | ||
Date, chron, yearmon, yearqtr, zoo, zooreg, timeDate, | ||
xts, its, ti, jul, timeSeries, fts or anything else that | ||
can be converted with as.POSIXlt} | ||
} | ||
\value{ | ||
numeric the fiscal quarter that the date-time occurs in | ||
} | ||
\description{ | ||
Fiscal quarters are a way of dividing the year into | ||
fourths. The first quarter (Q1) comprises January, | ||
February and March; the second quarter (Q2) comprises | ||
April, May, June; the third quarter (Q3) comprises July, | ||
August, September; the fourth quarter (Q4) October, | ||
November, December. | ||
} | ||
\examples{ | ||
x <- ymd(c("2012-03-26", "2012-05-04", "2012-09-23", "2012-12-31")) | ||
# 1 2 3 4 | ||
} | ||
\keyword{chron} | ||
\keyword{manip} | ||
\keyword{methods} | ||
\keyword{utilities} | ||
|