From tkeitt at mail.utexas.edu  Tue Aug 10 16:22:12 2004
From: tkeitt at mail.utexas.edu (Timothy H. Keitt)
Date: Tue Aug 10 16:22:17 2004
Subject: [Rd] Subsetting time series
In-Reply-To: <16664.33196.178734.309201@gargle.gargle.HOWL>
References: <41183AA0.8010203@stat.auckland.ac.nz>
	<Pine.LNX.4.44.0408100537040.13142-100000@gannet.stats>
	<16664.33196.178734.309201@gargle.gargle.HOWL>
Message-ID: <33726.66.220.230.120.1092147732.squirrel@66.220.230.120>

The basic concepts here seem to be "implicitly indexed," with a start and
step, and "explicitly indexed," where each value has a time (or space)
stamp (I've left out for the moment whether these need to be monotonic).
Since implicitly indexed can mimic explicitly indexed simply by generating
the time stamps on the fly, it makes sense for implicitly indexed to
inherit from explicitly indexed. Subsampling of an implicitly indexed
array can then safely return an explicitly indexed object from
].implicite.series (or whatever naming is appropriate).

Cheers,
THK

Martin Maechler said:
>>>>>> "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.
>
> I don't much like the current behavior of "[.ts" either.
> It should either work by returning the "ts" object in the
> equidistant case  and give a warning (at least) in the
> non-equidistant case.
> OTOH, intuitively, when 'ind' has length 1,  x[ind] should just
> give a number... [grumble..]
> But maybe it's only a very small performance hit when that
> continues to carry the "ts" class attribute along.
>
> If we think of the data.frame analogue, we might consider
> defining "[[.ts" for extracting numbers and "[.ts" to always
> return a time series or an error.
> But that is probably too much incompatible to current behavior.
>
> Martin
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


--
Timothy H. Keitt            http://www.keittlab.org/
Assistant professor
Section of Integrative Biology
University of Texas at Austin


[Rd] Subsetting time series
Timothy H. Keitt