Running into a real head-scratcher and not sure of how to resolve. Really hoping some of you may be able to help. Also, first time I've ever contributed to StackOverflow....yay!
library(tidyverse)
library(lubridate)
start_date <- ymd("2014-06-28")
end_date <- ymd("2019-06-30")
PayPeriod_EndDate <- seq(start_date, end_date, by = '2 week')
PayPeriod_Interval <- int_diff(PayPeriod_EndDate)
This creates a vector of intervals, with each interval representing a pay period of two weeks in length. This is part one, and part one is relatively easy (though still took awhile to figure out, ha).
Part two contains a vector of dates.
Dates <- c("2014-07-08", "2018-10-20", "2018-12-13", "2018-12-13", "2018-12-06", "2018-11-30", "2019-01-16", "2019-01-23", "2019-03-15", "2018-10-02")
I want to identify Dates %within%
Intervals, with the output being the interval that each date is within. So Date "2014-07-08"
will be assigned 2014-06-28 UTC--2014-07-12 UTC
, since this dates is within this interval.
A very similar problem seems to have been explored here...https://github.com/tidyverse/lubridate/issues/658
I have attempted the following
ymd(Dates) %within% PayPeriod_Interval
However, the result only calculates for the first element in the Dates vector. I have since tried various combinations of for loops, mutating into factors, etc... with little progress. This is work related so am really on a time-deficit and will be monitoring this post throughout the day and into the weekend.
Best and thank you! James