#' Find the quarter in a financial year for a given month
#'
#' Returns 1 for April, May, June, 2 for July etc.,
#'
#' @param month Month, 1-12, numeric.
#'
#' @return Quarter, 1-4, numeric
#' @export
financial_quarter <- function(month) {
# Sort out inputs -----------------------------------------------------------
month <- as.integer(month)
if (month %!in% 1L:12L | !is.numeric(month)) {
stop("Enter a month 1-12.")
}
# Return financial quarter --------------------------------------------------
dplyr::case_when(
month %in% c(1, 2, 3) ~ 4,
month %in% c(4, 5, 6) ~ 1,
month %in% c(7, 8, 9) ~ 2,
month %in% c(10, 11, 12) ~ 3)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.