Skip to content

Instantly share code, notes, and snippets.

@mmparker
Created January 30, 2014 16:50
Show Gist options
  • Select an option

  • Save mmparker/8713036 to your computer and use it in GitHub Desktop.

Select an option

Save mmparker/8713036 to your computer and use it in GitHub Desktop.
Calculate the last day of a quarter, given year and quarter
# Calculate the date of the last day of a given quarter by pasting
# together its first day, adding three months, and subtracting a day.
# Very elegance
# Such vectorized
calc_qtr_end <- function(year, qtr) {
require(lubridate) # Easiest way to add a month to a date
(as.Date(paste(year, qtr * 3, "01", sep = "-")) %m+% months(1)) - 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment