Creating a date vector starts from a specific date and moves forward n units

To use ggplot to work with time series, I need to take a bunch of predicted values ​​and put them in the data file along with the corresponding dates.

I used the following code to declare my starting vector a ts

name <- ts(name, frequency=12, start=c(2007,1))

Then I fit the model using

fit <- auto.arima (name)

and prediction and prediction intervals, as shown below.

name.for <- forecast(fit, 15)
name.for.low <- name.for$lower[,2]
name.for.up <- name.for$upper[,2]

I know that I hope to make a date vector that starts where the time loop announced above ends and goes forward n months

I think I can use something like:

seq(as.Date('X'), length.out=n, by='1 month')

However, I want X to be dynamic and calculated from the time series vector above

+4
2

:

library(lubridate)
jan31 <- ymd("2016-01-31")
n <- 4
jan31 %m+% months(n)
#[1] "2016-05-31"
n <- 5
jan31 %m+% months(n)
#[1] "2016-06-30"
+2

?

ts2<- ts(1:28, frequency=12, start=last(time(name )) )
as.Date(ts2)

: , , , ts2<- ts(1:28, frequency=12, start=last(time(name )+1*deltat(name)) )

0

Source: https://habr.com/ru/post/1655796/


All Articles