[R-SIG-Finance] [R-sig-finance] Time index conversion in zoo/xts

Jeff Ryan jeff.a.ryan at gmail.com
Wed Mar 26 18:35:23 CET 2008


Hi Yuri,

I think the issue is that you are sub-setting and then changing only
_part_ of the index, which leaves part of it unadjusted and
potentially overlapping.  An reproducible example would be definitive,
but this is my attempt to explain what I _suspect_ is happening.

Create an xts/zoo object from 6:55 to 7:04 - 10 minutes (so as to fit
in this email),
and assign the index to 'timestamps'
> myxts <- xts(runif(10,40,50),as.POSIXct('2007-01-01 06:55:00')+seq(0,600-1,by=60))
> timestamps <- index(myxts)
> timestamps
 [1] "2007-01-01 06:55:00 UTC" "2007-01-01 06:56:00 UTC"
 [3] "2007-01-01 06:57:00 UTC" "2007-01-01 06:58:00 UTC"
 [5] "2007-01-01 06:59:00 UTC" "2007-01-01 07:00:00 UTC"
 [7] "2007-01-01 07:01:00 UTC" "2007-01-01 07:02:00 UTC"
 [9] "2007-01-01 07:03:00 UTC" "2007-01-01 07:04:00 UTC"

This is the subset you asked for:
> timestamps[format(timestamps,'%H:%M') < '07:00']
[1] "2007-01-01 06:55:00 UTC" "2007-01-01 06:56:00 UTC"
[3] "2007-01-01 06:57:00 UTC" "2007-01-01 06:58:00 UTC"
[5] "2007-01-01 06:59:00 UTC"

Which is only 50% of _my_ data

This is it advanced by 10 minutes:
> timestamps[format(timestamps,'%H:%M') < '07:00']+360
[1] "2007-01-01 07:01:00 UTC" "2007-01-01 07:02:00 UTC"
[3] "2007-01-01 07:03:00 UTC" "2007-01-01 07:04:00 UTC"
[5] "2007-01-01 07:05:00 UTC"

As you may be quick to see, you have duplicated part of the original
timestamps index.

So replacing via:
> timestamps[format(timestamps,'%H:%M') < '07:00'] <- timestamps[format(timestamps,'%H:%M') < '07:00']+360
> timestamps
 [1] "2007-01-01 07:01:00 UTC" "2007-01-01 07:02:00 UTC"
 [3] "2007-01-01 07:03:00 UTC" "2007-01-01 07:04:00 UTC"
 [5] "2007-01-01 07:05:00 UTC" "2007-01-01 07:00:00 UTC"
 [7] "2007-01-01 07:01:00 UTC" "2007-01-01 07:02:00 UTC"
 [9] "2007-01-01 07:03:00 UTC" "2007-01-01 07:04:00 UTC"
>

causes duplicate entries.

I suspect this is what is happening - and why you are getting the
warnings and errors. Without the actual data to work with though it is
only a best guess.

Jeff

>




On Wed, Mar 26, 2008 at 10:43 AM, Yuri Volchik <yuri.volchik at gmail.com> wrote:
>
>  Hi to all,
>
>  presume question mostly is to Gabor or Jeff:
>  when i add milliseconds to time index and create zoo (xts) object using some
>  simple code everything works fine (index (zoo,xts) has unique elements), but
>  when i added one line to correct for DST changes :
>
>  timestamps[format(timestamps,"%H:%M")<'07:00']<-timestamps[format(timestamps,"%H:%M")<'07:00']+3600
>
>  suddenly i get a warning about non-unique indices and later i get an error
>  when trying to merger xts (zoo) object.
>
>  I checked classes before and after this line and those seems to be the same
>  "POSIXt"  "POSIXlt".
>
>  Thanks
>
>
>  --
>  View this message in context: http://www.nabble.com/Time-index-conversion-in-zoo-xts-tp16304015p16304015.html
>  Sent from the Rmetrics mailing list archive at Nabble.com.
>
>  _______________________________________________
>  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.
>



-- 
There's a way to do it better - find it.
Thomas A. Edison



More information about the R-SIG-Finance mailing list