[R-SIG-Finance] Adding milliseconds to zoo object

Gabor Grothendieck ggrothendieck at gmail.com
Wed Dec 26 20:17:58 CET 2007


On Dec 26, 2007 11:40 AM, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> Even though non-unique times form illegal zoo objects, both
> zoo() and read.zoo() will allow you to create such illegal zoo objects
> with a warning, rather than an error, in order to give you a chance to
> fix them up into legal ones.  You can still extract and replace the times
> in case you want to apply jitter or fixed increments and aggregate.zoo
> will still work in case you want to summarize all points with the same
> time into a single point. Here is an example of adding increments via
> interpolation with numeric times:
>
> > library(zoo)
> > z <- zoo(11:15, c(1, 1, 2, 2, 5))
> Warning message:
> In zoo(11:15, c(1, 1, 2, 2, 5)) :
>  some methods for "zoo" objects do not work if the index entries in
> 'order.by' are not unique
> > z
>  1  1  2  2  5
> 11 12 13 14 15
> > time(z) <- na.approx(ifelse(duplicated(time(z)), NA, time(z)))
> > z
>  1 1.5   2 3.5   5
>  11  12  13  14  15

Just one follow up.  The code above will only work if the last
point in the series is at a unique time point.

Here is a solution that also deletes trailing duplicates so
it should be ok even in that case:

> z <- zoo(11:15, c(1, 1, 2, 2, 2))
Warning message:
In zoo(11:15, c(1, 1, 2, 2, 2)) :
  some methods for "zoo" objects do not work if the index entries in
'order.by' are not unique
> time(z) <- na.approx(ifelse(duplicated(time(z)), NA, time(z)), na.rm = FALSE)
> z <- z[!is.na(time(z))]
> z
  1 1.5   2
 11  12  13


>
>
>
> On Dec 26, 2007 11:11 AM, Yuri Volchik <volchik2000 at list.ru> wrote:
> > Thank you for replies Gabor & Brian,
> >
> > Yes I did read the previous threads concerning similar problem and I saw
> > Dirk's post:
> >
> > >> I pad my high-resolution times with an eps=1.0-6 to make them distinct,
> > if
> > >> need be
> >
> > So I presume the question is better formulated as how to pad high-resolution
> > times with an eps to make them distinct given that we have original index
> > with non-unique values, but order in the file reflect their relative
> > position inside this time interval.
> >
> > 2007-12-24 06:14:00  22.00
> > 2007-12-24 06:14:00  22.00
> > 2007-12-24 06:15:00  22.00
> > 2007-12-24 06:15:00  22.00
> >
> > My current idea is to convert timestamps to factors and run tapply on them,
> > but probably there is a better solution.
> >
> >
> > _______________________________________________
> > 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