Combine univariate time series
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