qtr: Assign a date to a quarter

View source: R/qtr.R

qtrR Documentation

Assign a date to a quarter

Description

The qtr functions take the first day of a quarter (the first of either January, April, July or October) and calculate the relevant quarter-related value from it.

  • qtr returns the current quarter in either short or long format.

  • qtr_end returns the last month in the quarter, either of the current or following quarter.

  • qtr_prev returns the previous quarter in long format.

Usage

qtr(first_day, format = c("long", "short"))

qtr_end(first_day, quarter = c("current", "next"))

qtr_prev(first_day)

Arguments

first_day

The first day of a quarter, supplied with Date class.

format

A character string specifying the format the quarter should be displayed in. Valid options are 'short' (Jan-Mar 2018) and 'long' (January to March 2018).

quarter

A character string. Specifies which quarter should have its final month returned. Valid options are 'current' and 'next'.

Examples

qtr(first_day = lubridate::dmy(01012018), format = "short")
qtr(first_day = lubridate::dmy(01102018), format = "long")

qtr_end(first_day = lubridate::dmy(01072018), quarter = "current")
qtr_end(first_day = lubridate::dmy(01042018), quarter = "next")

qtr_prev(first_day = lubridate::dmy(01012018))

Public-Health-Scotland/hsmr documentation built on June 24, 2024, 1:48 a.m.