previous_quarter: Return a previous quarter

View source: R/previous_quarter.R

previous_quarterR Documentation

Return a previous quarter

Description

Given the latest quarter as a string in the format "2020 Q4", returns a string in the same format representing the previous quarter, or previous quarters going further back if desired.

Usage

previous_quarter(quarter, quarters_ago = 1)

Arguments

quarter

The latest quarter as a string, starting with the year, a 'q' or 'Q', then the quarter number (1,2,3 or 4), e.g. "2020 Q2".

quarters_ago

Number of quarters to go back. Default is 1. If negative, the number of quarters to go forward.

Value

A character object.

Examples

previous_quarter("2020 Q1") # returns "2019 Q4"
previous_quarter("2020 Q1", 3) # returns "2019 Q2"

moj-analytical-services/mojrap documentation built on July 30, 2023, 4:43 p.m.