[R] Transposing forecasts results from nnetar function and turn them into a data frame
Paul Bernal
paulbernal07 at gmail.com
Thu Mar 16 19:34:01 CET 2017
Dear friends,
I am currently using R version 3.3.3 (64-bit) and used the following code
to generate forecasts:
> library(forecast)
>
> library(tseries)
‘tseries’ version: 0.10-35
‘tseries’ is a package for time series analysis and computational
finance.
See ‘library(help="tseries")’ for details.
> DAT<-read.csv("TrainingData.csv")
>
> TSdata<-ts(DAT[,1], start=c(1994,10), frequency=12)
>
> TSmodel<-nnetar(TSdata)
>
> TSmodelForecast<-forecast(TSmodel, h=24)
>
> TSmodelForecast
The problem is that the output comes in this fashion:
Jan Feb Mar Apr May Jun Jul Aug
Sep Oct
2017 10 20 15 40 9 8 21 21
19 18
2018 34 15 7 6 10 11
The format I would like to have is the following:
Date Forecast
Jan-2017 10
Feb-2017 20
Mar-2017 15
Apr-2017 40
May-2017 9
Jun-2017 8
Jul-2017 21
Aug-2017 21
Sep-2017 19
etc etc
Is there a way to make the results look like this?
Attached is a dataset as a reference.
Best regards,
Paul
More information about the R-help
mailing list