From maechler at stat.math.ethz.ch  Tue Aug 10 10:29:58 2004
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Tue Aug 10 10:30:00 2004
Subject: [Rd] Subsetting time series
In-Reply-To: <Pine.LNX.4.44.0408100909110.24918-100000@gannet.stats>
References: <16664.33196.178734.309201@gargle.gargle.HOWL>
	<Pine.LNX.4.44.0408100909110.24918-100000@gannet.stats>
Message-ID: <16664.34694.648308.383000@gargle.gargle.HOWL>

>>>>> "BDR" == Prof Brian Ripley <ripley@stats.ox.ac.uk>
>>>>>     on Tue, 10 Aug 2004 09:11:39 +0100 (BST) writes:

    BDR> On Tue, 10 Aug 2004, Martin Maechler wrote:
    >> >>>>> "BDR" == Prof Brian Ripley <ripley@stats.ox.ac.uk>
    >> >>>>>     on Tue, 10 Aug 2004 05:47:28 +0100 (BST) writes:
    >> 
    BDR> 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?
    >> 
    BDR> There is a [.ts, in src/library/stats/R/ts.R, and it is documented 
    BDR> (?"[.ts").
    >> 
    >> >> Have you had a look at "window"?  The problem with "["
    >> >> its that it can produce non-contiguous sets of values.
    >> 
    BDR> Yes.
    >> 
    >> indeed.  window() is what we have been advocation for a long
    >> time now ... (but see below).
    >> 
    BDR> If you look in the sources for [.ts you will see,
    BDR> commented, the code that was once there to handle cases
    BDR> where the index was evenly spaced.  But it was removed
    BDR> long ago in favour of window().  I tried to consult the
    BDR> logs, but it seems that in the shift from CVS to SVN
    BDR> recently I can't get at them.  I think the rationale
    BDR> was that x[ind] should always produce an object of the
    BDR> same class.
    >> 
    >> well, that can't have been the only rationale since now
    >> x[ind] is *not* of the same class - when the "ts" property is
    >> lost in any case.

    BDR> `always of the same class' : for all (non-trivial)  values of ind.

aah!  please excuse my mis-interpretation of meaning "same class
as original x".

Martin


[Rd] Subsetting time series
Martin Maechler