[R] Updating a Time Series After Forecast()
Berend Hasselman
bhh at xs4all.nl
Fri Jan 15 13:02:58 CET 2016
> On 14 Jan 2016, at 22:36, Lorenzo Isella <lorenzo.isella at gmail.com> wrote:
>
> Dear All,
> Perhaps I am drowning in a cup of water, since I am positive that the
> answer will be a one-liner.
> Consider the following short script
>
>
> ########################################################
> library(forecast)
>
> ts2<-structure(c(339130, 356462, 363234, 378179, 367864, 378337, 392157,
> 402153, 376361, 392204, 403483, 414034, 391967, 406067, 419464,
> 434913, 410102, 424795, 437073, 448827, 415569, 430561, 444719,
> 455764, 419892, 444190, 454648, 466312, 439922, 448963, 465153,
> 475621, 445502, 457198, 473573, 485764, 463895, 470274, 484390,
> 490678, 478003, 483570, 499141, 509216, 481395, 492345, 511184,
> 513420, 483757, 490884, 514966, 515457, 497614, 510139, 523467,
> 526406, 499784, 519033, 532009, 531260, 521539, 532590, 553118,
> 557725, 548321, 556832, 578087, 578120, 566116, 580571, 587993,
> 569985, 534326, 539641, 564824, 568445, 558614, 570192, 594584,
> 598305, 593769, 598278, 620147, 615884, 611033, 609304, 630458,
> 624325, 614356, 627192, 649324, 645988, 642965, 645125, 669471,
> 665529, 664248, 669670, 694719), na.action = structure(1:64, class =
> "omit"), .Tsp = c(1991,
> 2015.5, 4), class = "ts")
>
> fit2 <- auto.arima(ts2, approximation=FALSE,trace=FALSE)
>
> pred2 <- forecast(fit2, h=2)
>
> #######################################################
>
> So, I have an original quarterly time series ts2 and a forecast for 2
> quarters pred2.
>
> I would like to combine ts2 and pred2 (just the prediction) into a new
> time series (in other words, just stretch a bit ts2).
> How can I do that?
A possible way is this
ts3 <- ts(c(ts2,pred2$mean),start=start(ts2),frequency=frequency(ts2))
Most likely there are more ways of getting what you want.
Berend
> Many thanks
>
> Lorenzo
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list