2

For work I need to find if a vector of dates falls on the week after Christmas. To do that, I thought the smartest first step would be to find the first day that falls in that period across the years I'm interested in. I've been able to use the method I'm using below for a number of holidays and special dates. This time however I've hit a wall in my understanding of how to work with dates. Please help me understand what I am doing wrong or what is happening under the surface to cause this error.

library(lubridate)
years_in_data <- 2008:2015

#Jan 1st
New_Years_Day <- ymd(paste0(years_in_data, "-01-01"), tz = "America/Anchorage")

#Dec. 26 - Dec. 31
Week_After_Christmas_start <- New_Years_Day + months(11) + day(25)

And the resulting error:

Error in as.POSIXlt.numeric(x, tz = tz(x)) : 'origin' must be supplied
cylondude
  • 1,816
  • 1
  • 22
  • 55
  • `day(25)` should be `days(25)`. – eipi10 Mar 27 '15 at 18:34
  • If your vector of dates is called `dates`, couldn't you get the dates that fall between Christmas and New Year's like this: `dates[month(dates)==12 & day(dates) %in% 26:31]`? (In this case you want `day`, not `days`). – eipi10 Mar 27 '15 at 18:43
  • My strategy is to just do ```dates %in% New_Years_Day```. I don't know which seems cleaner to everyone though. That's just for one day though. – cylondude Mar 27 '15 at 19:41
  • Do you really need a time zone when you only have dates and no times? Perhaps this would be sufficient: `as.Date(paste(years_in_data, 12, 25, sep = "-"))` – G. Grothendieck Mar 27 '15 at 21:09

0 Answers0