I want to automate the forecasting procedure for a data set that I have. I have a three years of daily historic data and I want to use 2 years as test data and one year as train data. I want to have rolling forecast which means that I read historic data+observed data for train set, and forecast for every 2 days ahead. Then I again read the data including the historic set and the two observed data and this process goes on until the whole train set is predicted. I want to automate the process. My code is like the following:
i <- 883
while (i < 912){
orders <- window(data$orders,end=i)
y <- msts(orders,seasonal.periods=c(7,365.25))
model <- tbats(y)
print(forecast(model,h=2,l=c(50,80)))
i <- i+2}
Instead of printing forecast for each 2 days, I prefer to have an empty dataframe and add the new forecasted values to that. However, I have a problem with understanding what is the data type that this line of code is generating:
forecast(model,h=2,l=c(50,80))
it generates three rows, the first row includes headers, second row shows point forecast, low 50% and high 50% prediction intervals and low 80% and high 80% prediction intervals. so it includes 5 columns. My only problem is that each time it wants to store these results in the data frame, it stores the first row which is the header row as well. I wonder how I can store only the last two rows in the data frame.
Thanks