Convert a weekly serie in time serie in R -


i have serie in way:

year    week    sale_amount 2016    16        85501 2016    12        74286 2016    14        87499 

how can convert in ts can use forecast in r?

just sort data in right way, , follow example of rob hyndman create weekly forecast (see line 3 on how define ts object).

install.packages("forecast")  library(forecast) gas <- ts(read.csv("http://robjhyndman.com/data/gasoline.csv", header=false)[,1],            freq=365.25/7, start=1991+31/365.25) bestfit <- list(aicc=inf) for(i in 1:25) {   fit <- auto.arima(gas, xreg=fourier(gas, k=i), seasonal=false)   if(fit$aicc < bestfit$aicc)     bestfit <- fit   else break; } fc <- forecast(bestfit, xreg=fourierf(gas, k=12, h=104)) plot(fc) 

enter image description here

the code & picture taken http://robjhyndman.com/hyndsight/forecasting-weekly-data/ find details on how apply other forecasting models.


Comments