Re: [Rd] Subsetting time series

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue 10 Aug 2004 - 14:47:28 EST


On Tue, 10 Aug 2004, Ross Ihaka wrote:

> Rob Hyndman wrote:
> > When part of a time series is extracted, the time series component is
> > lost. e.g.,
> > x <- ts(1:10)
> > x[1:4]
> >
> > It would be nice if there was a subsetting function [.ts to avoid this
> > problem. However, it is beyond my R-coding ability to produce such a
> > thing. Is someone willing to do it?

There is a [.ts, in src/library/stats/R/ts.R, and it is documented (?"[.ts").

> Have you had a look at "window"? The problem with "["
> its that it can produce non-contiguous sets of values.

Yes. If you look in the sources for [.ts you will see, commented, the code that was once there to handle cases where the index was evenly spaced. But it was removed long ago in favour of window(). I tried to consult the logs, but it seems that in the shift from CVS to SVN recently I can't get at them. I think the rationale was that x[ind] should always produce an object of the same class.

-- 
Brian D. Ripley,                  ripley@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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Aug 10 14:50:32 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 08:59:17 EST