Created
January 30, 2014 16:50
-
-
Save mmparker/8713036 to your computer and use it in GitHub Desktop.
Calculate the last day of a quarter, given year and quarter
This file contains hidden or 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
| # 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