I have a data frame with a list of enddates of fiscal quarters between 2014 and 2021. I want to create a separate column with the beginning of each of these quarters. Note that the format is YYYY-MM-DD. It looks like this:
df <- data.frame(end = c("2014-12-31", "2015-03-31","2015-06-30", "2015-09-30", "2015-12-31", "2016-03-31"))
The dates quarters are always from
- Jan 1st to Mar 31st
- Apr 1st to Jun 30th
- Jul 1st to Sep 30th
- Oct 1st to Dec 31st
My current code works by creating a separate column for each date with an ifelse statement and then adding them all together like this:
hmd$dtime_2 <- ifelse(hmd$dtime == "2015-03-31","2014-01-01", "")
hmd$dtime_3 <- ifelse(hmd$dtime == "2015-06-30", "2015-04-01", "")
hmd$dtime_4 <- ifelse(hmd$dtime == "2015-09-30","2015-07-01", "")
hmd$dtime_5 <- ifelse(hmd$dtime == "2015-12-31", "2015-10-01", "")
I know that there has to be an easier way to do this and I'd appreciate the help!