Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.LNX.4.61.0504131003500.7213@gannet.stats>
Date: 2005-04-13T09:07:42Z
From: Brian Ripley
Subject: Combine univariate time series
In-Reply-To: <s25cf0b3.099@du-gwpo.emp-eaw.ch>

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,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595