Data:
DB <- data.frame(orderID = c(1,2,3,4,5,6,7,8,9,10),
orderDate = c("1.1.14","8.4.14","17.4.14","29.3.12","29.7.14",
"2.8.14","21.9.14","4.10.14","30.11.14","9.4.06"),
Expected outcome [Hope I counted the number of days right]:
orderDuringPresentShoppingWeekseasternpast =c("No", "Yes", "Yes", "Yes", "No", "No", "No", "No", "No", "Yes")
Hi guys,
I think I have now the most complex/difficult question I asked till now:but perhaps someone is smarter than me and can solve the prob in a min :)
I have different time spans with dates in it for the public holiday eastern. But not only for this year-also for the past 10. As everybody knows eastern is on a different date every year: so I can´t fix it on a specific date for every year.
1.I want to give out a "yes" if the order happend on the easterdays or in a span of 14days before easter sunday during the last years and a "no" if not. I already made some timespans for the past 10years:
spanEasternpast
[1] 2015-03-22 UTC--2015-04-05 UTC 2014-04-06 UTC--2014-04-20 UTC 2013-03-17 UTC--2013-03-31 UTC 2012-03-25 UTC--2012-04-08 UTC
[5] 2011-04-10 UTC--2011-04-24 UTC 2010-03-21 UTC--2010-04-04 UTC 2009-03-29 UTC--2009-04-12 UTC 2008-03-09 UTC--2008-03-23 UTC
[9] 2007-03-25 UTC--2007-04-08 UTC 2006-04-02 UTC--2006-04-16 UTC 2005-03-13 UTC--2005-03-27 UTC
Tried it already like this, but it´s not working:
Easternpast <- Easter(currentYear:(currentYear -10))
spanEasternpast <- new_interval (ymd(Easternpast-ddays(14)), ymd(Easternpast))
spanEasternpast
[1] 2015-03-22 UTC--2015-04-05 UTC 2014-04-06 UTC--2014-04-20 UTC 2013-03-17 UTC--2013-03-31 UTC 2012-03-25 UTC--2012-04-08 UTC
[5] 2011-04-10 UTC--2011-04-24 UTC 2010-03-21 UTC--2010-04-04 UTC 2009-03-29 UTC--2009-04-12 UTC 2008-03-09 UTC--2008-03-23 UTC
[9] 2007-03-25 UTC--2007-04-08 UTC 2006-04-02 UTC--2006-04-16 UTC 2005-03-13 UTC--2005-03-27 UTC (so this part with the right span is working)
DB$orderDuringPresentShoppingWeekseasternpast <- ifelse(DB$orderDate%within%spanEasternpast == TRUE, "Yes", "No")
Hope your able to show me what´s wrong or show me another posibility to solve the prob....
Cheers and THX!