Gracos Gracos - 20 days ago 6
R Question

R timeDate package - holidays output issue

I need to make a list of holidays that includes NYSE holidays plus Columbus Day and Veterans Day. For that I used

timeDate
package as follows:

library(timeDate)
years <- 2015

holidayEIA <- function(x){ c(holidayNYSE(x),
as.Date(USColumbusDay(x)),
as.Date(USVeteransDay(x))) }
holidayEIA(years)


The output includes two dates in 1969. It also adds a time next to the date. I could strip the time stamp and elements containing 1969 with a line of code. Yet, would prefer those to not be present from the very beginning.

#Output
[1] [2015-01-01 00:00:00] [2015-01-19 00:00:00] [2015-02-16 00:00:00]
[4] [2015-04-03 00:00:00] [2015-05-25 00:00:00] [2015-07-03 00:00:00]
[7] [2015-09-07 00:00:00] [2015-11-26 00:00:00] [2015-12-25 00:00:00]
[10] [1969-12-31 23:38:40] [1969-12-31 23:39:10]


If I run
holidayNYSE(2015)
,
USColumbusDay(2015)
or
USVeteransDay(2015)
separately the resulting timeDate objects have no time stamp, and there is no year 1969. I do not understand why running all three together results in a time stamp added and in the 1969 issue. Of course I could also run the three independently and them bind them. That's just a patch; I'd rather not have to do that if I can avoid it. Thank you for your help.

Answer

This solved both issues:

library(timeDate)
years <- 2015

holidayEIA <- function(x){ c(holidayNYSE(x), 
                             USColumbusDay(x)@Data+ 14400, 
                             USVeteransDay(x)@Data+ 18000)}
holidayEIA(years)
Comments