[R-SIG-Finance] Writing code that works with a variety of time series classes

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 4 20:28:25 CEST 2008


Since zoo has made a concerted effort to be interoperable
the easiest thing to do is convert the input to zoo and then extract
the data and index portions from that.  The dyn package
is an example that can handle many time series formats
and that is the strategy it takes.

Thus coredata(as.zoo(x)) and time(as.zoo(x)) will generally work.
Also just time(x) will also usually work for the second case.

The above works with a larger set of time series classes than in
your example and the set it covers includes all or nearly all time series
classes defined in the various R packages on CRAN.

The upcoming release of zoo supports conversion among
additional time series packages in addition to the many
already supported now and these conversions have already
been fully developed.

On Sat, Oct 4, 2008 at 2:14 PM, Ajay Shah <ajayshah at mayin.org> wrote:
> I'm writing a function where I want to support two cases:
>    - caller supplies a pure numeric
> or
>    - caller supplies a time series object
>
> For the latter case, R now has a variety of time series classes : ts,
> zoo, its, xts, etc. I only require two operations:
>
>     I want to pull out the datetime stamps (e.g. index(a.zoo))
>     I want to then convert down to a numeric (e.g. as.numeric(a.zoo))
>
> Between all the people building time series classes, is there an
> agreement on some minimal set of functions that will always be
> supported? Do index(z) and as.numeric(z) work consistently across all
> the time series classes? And, I think we need a function is.tsclass()
> which reports TRUE if the object supplied is a zoo, its, ts or xts.
>
> --
> Ajay Shah                                      http://www.mayin.org/ajayshah
> ajayshah at mayin.org                             http://ajayshahblog.blogspot.com
> <*(:-? - wizard who doesn't know the answer.
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list