Hi Andres,
Thank you again for the detailed example that helps me a lot with starting up. I tried doing the following and received some error. May you please take a look at my progress whenever time is made available for you?
(1) ###### I created holidays to include all these. While Remembrance day isn't in the system, I put "11-11" following the example you provided. #######
holidays <- c( Easter(1979:2018)
-
, CACanadaDay(1979:2018)
-
, CAThanksgivingDay(1979:2018)
-
, CACivicProvincialHoliday(1979:2018)
-
, CALabourDay(1979:2018)
-
, CAVictoriaDay(1979:2018)
-
, ChristmasDay(1979:2018)
-
, NewYearsDay(1979:2018)
-
, GoodFriday(1979:2018)
-
, BoxingDay(1979:2018)
-
, "11-11" )
****** Warning message: In FUN(X[[i]], ...) : NAs introduced by coercion ******* <-------- I'm not sure what this means, but it seems to be a problem from my "11-11"
(2) ####### Then I created the data frame and put in FIFA$Date as my "date vector" since the name of my dataset is "FIFA", and I have a vector of daily dates called "Date" that is in the format Y%/M%/D%. ------> after that, I got an error message as shown below ######
Date.frame <- data.frame(stringsAsFactors = FALSE, date = FIFA$Date)
library(dplyr)
library(lubridate)
library(stringr)
Date.frame %>%
- mutate(date = ymd(FIFA$Date),
-
Ht = if_else(paste(str_pad(day(FIFA$Date), 2, pad = "0"),
-
str_pad(month(FIFA$Date), 2, pad = "0"),
-
sep = "-") %in% holidays, 1, 0))
***Error in match(x, table, nomatch = 0L) : 'match' requires vector arguments
(3) ###### Lastly, I want to create dummy " Ht_prev1 " & " Ht_nxt1 " as two dummy variables that ==1 when its the 1 previous business day of a non-weekend holiday that I already generated ; and " Ht_nxt1 " would be the next business day. Here's what I tried and the error messages I am getting. ######
METHOD 1
Ht_prev1 <- ifelse(FIFA$Dates == holidays, holidays - 1, FIFA$Dates)
Error in FIFA$Dates == holidays :
comparison (1) is possible only for atomic and list types
Ht_nxt1 <- ifelse(FIFA$Dates == 'holidays' + 1 , FIFA$Dates)
Error in "holidays" + 1 : non-numeric argument to binary operator
METHOD 2
library(dsa)
Holiday(dates=timeDate::holidays, shift=-1)
Error: 'holidays' is not an exported object from 'namespace:timeDate'
Holiday(dates=timeDate::holidays, shift=+1)
Error: 'holidays' is not an exported object from 'namespace:timeDate'
METHOD 3
library(tis)
nextBusinessDay(FIFA$Date, holidays = holidays, goodFriday = F, board = F, inaug = F)
Error in match(ymd(z), holidays, nomatch = 0) :
'match' requires vector arguments
previousBusinessDay(FIFA$Date, holidays = holidays, goodFriday = F, board = F, inaug = F)
Error in match(ymd(z), holidays, nomatch = 0) :
'match' requires vector arguments