Search code examples
rforecast

Appending time series


If I have 2 time series like this:

y <- ts(rnorm(12), start = c(2000, 1), end = c(2000, 12), freq = 12)
z <- ts(rnorm(2), start= c(2001, 1), end = c(2001, 2), freq = 12)
ts.union(y, z)

How can I append the 2nd series, but with a single column? The result should be a ts again (not a xts).


Solution

  • You need to reassign your ts by combining two ts and adjusting start, frequency as follow:

    ts(c(y,z), start=start(y), frequency=frequency(y))
    

    Output:

    str(df)
    Time-Series [1:14] from 2000 to 2001: 0.511 -0.0249 -1.353 0.1526 0.9596 ...