[R] Programatic Method for Holiday Dummy Variables

Idgarad idgarad at gmail.com
Tue May 20 19:21:21 CEST 2008


I am working on a weekly analysis and would like to look into the
effects of a holiday. As I only get weekly data how can I populate,
automagically, a series of dummy variables that are aligned with my
data.

---- Snip -----

channel1 <- odbcConnectExcel("D:/RSTATS/metrics.xls")
sqlTables(channel1)
sh1 <- sqlFetch(channel1, "Actuals$")

channel2 <- odbcConnectExcel("D:/RSTATS/events.xls")
sqlTables(channel2)
sh2 <- sqlFetch(channel2, "data$")


tsU000=ts(sh1$U000,start=c(2004,1),freq=52)
summary(tsU000)

#Variable
forecastDistance <- 52
#Grab Existing Regressors
cReg <- sh2[1:length(tsU000),-1]
#Grab X Future Regressors equal to the forecastDistance
fReg <- sh2[length(tsU000):(length(tsU000)+forecastDistance),-1]
---snip----

Somewhere in there I need to append to cReg a series of holiday dummy
variables but here is the catch, it's weekly data.

First How can I get an array of holidays in the first place aligned on
weeks?

e.g.

week,xmas,newyears,holloween,cinco,...,qwanza,
1,0,0,0,0,0,...,0
2,0,0,0,0,0,...,0
3,0,0,0,0,0,...,0
4,0,0,0,0,0,...,0
5,0,0,0,0,0,...,0
..
52,1,0,0,0,0,...,0

then how do I append the holiday array to the cReg array?

Help I am confused and bewildered



More information about the R-help mailing list