I have one data frame, which is composed of three columns(PIT,CIT and VAT). My intention is to make forecast with each of this three times series with Forecast package. For that reason I convert data frame into ts object.
Now I want to make forecasting with snaive function which is part from Forecast package.So I wrote this lines of code:
SNAIVE_PIT<-snaive(TS_REVENUES[, 'PIT'],h=5)
SNAIVE_CIT<-snaive(TS_REVENUES[, 'CIT'],h=5)
SNAIVE_VAT<-snaive(TS_REVENUES[, 'VAT'],h=5)
But my intention is to simplify this code with some function like: loop,for or other function, which can automatically calculate forecasting for each of this three times series(PIT,CIT and VAT) ? I am asking this because this time series is only small part of whole series and I must to simplify this forecasting procedures.
#CODE
library(forecast)
# Making data frame
DATA_SET<-data.frame(
PIT=seq(1, 48, by = 2),
CIT=seq(1, 24, by = 1),
VAT=seq(1, 94, by = 4)
)
View(DATA_SET)
# Making TS object
TS_REVENUES<-ts(DATA_SET,start=c(2016,1),frequency = 12)
# Extracting column names from TS object
COL_NAMES_TS<-TS_REVENUES[0:0,]
COL_NAMES_TS
# Making forecasting with Forecast package
SNAIVE_PIT<-snaive(TS_REVENUES[, 'PIT'],h=5)
SNAIVE_CIT<-snaive(TS_REVENUES[, 'CIT'],h=5)
SNAIVE_VAT<-snaive(TS_REVENUES[, 'VAT'],h=5)