I have a dataset with "Time, Region, Sales" variables and I want to forecast sales for each region using ARIMA or ETS(SES) using library(forecast)
. There are a total of 70 regions and all of them have 152 observations each and (3 years of data). Something like this:
Week Region Sales
01/1/2011 A 129
07/1/2011 A 140
14/1/2011 A 133
21/1/2011 A 189
... ... ...
01/12/2013 Z 324
07/12/2013 Z 210
14/12/2013 Z 155
21/12/2013 Z 386
28/12/2013 Z 266
So, I want R to treat every region as a different dataset and perform an auto.arima
. I am guessing a for loop should be an ideal fit here but I miserably failed with it.
What I would ideally want it to do is a for loop to run something like this (an auto arima for every 152 observations):
fit.A <- auto.arima(data$Sales[1:152])
fit.B <- auto.arima(data$Sales[153:304])
....
fit.Z <- auto.arima(data$Sales[10490:10640])
I came across this but while converting the dataframe into timeseries, all I got is NAs.
Any help is appreciated! Thank you.