Re: [R] Combine univariate time series

From: Prof Brian Ripley <>
Date: Wed 13 Apr 2005 - 19:07:42 EST

On Wed, 13 Apr 2005, Joerg Klausen wrote:

> I have two univariate time series (class ts) describing the same
> variable. They have the same resolution, but span different periods in
> time with a big gap in between. I need to append one to the other such
> that they are one object, with the gap filled with NAs. The method
> ts.union produces a multivariate time series where the time axis is
> correct, but the individual time series are not combined into one.

Use window() to create an extended series, then indexing to insert the other in the correct place. E.g.

x1 <- ts(1:10, start=1900)
x2 <- ts(70:80, start=1970)
xx <- window(x1, end=1980, extend=TRUE)

xx[71:81] <- x2
Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Wed Apr 13 19:13:07 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:07 EST