1 ## File: createCalendar.r
2 ## Description: Create the calendar transitions to be used on KWF predictor
3 ## Author: jc @ September 2015
5 ## Function: irishCalendar
6 ## Description: Create the calendar with day of the week and daytype.
7 ## (It is the first step, then we need to obtain the transitions)
8 irishCalendar <- function(from, to){
10 y0 <- as.character(substr(from, 1, 4))
11 y1 <- as.character(substr(to, 1, 4))
13 IRholidays <- c("NewYearsDay",
18 "GBSummerBankHoliday", # august holiday
25 jf <- holiday(year = years, Holiday = IRholidays)
26 jf <- sort(unique(jf))
27 dts <- timeSequence(from = paste(y0, '01', '01', sep = '-'),
28 to = paste(y1, '12', '31', sep = '-'))
29 wday <- dayOfWeek(dts)
31 for(d in 1:length(wdayf)){
33 if(dts[d] == jf[fpos]){
35 if(fpos < length(jf)) fpos <- fpos + 1
39 res <- data.frame(dow = wday, daytype = wdayf)
40 i0 <- which(rownames(res) == from)
41 i1 <- which(rownames(res) == to)
47 # Call irishCalendar to create the calendar.
48 myCal <- irishCalendar(from="2011-01-01", to= "2013-12-31")
51 # Obtention of the transitions
52 gr <- paste(myCal$daytype[1:(n - 1)], myCal$daytype[2:n], sep = '_')
53 gr[gr == "Hol_Hol"] <- "Sun_Hol"
54 myCal$gr <- c(gr, "Sat_Sun")
56 # Write output to a file
57 # write.table(file = "calendar_ir.txt", myCal)