[R-SIG-Finance] Index time change when coercing zoo object to xts

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jul 23 14:10:10 CEST 2009


As another responder mentioned we really need it in a reproducible
form; however, we can guess that the source of the problem is that
zoo represents all times in their original class, presumably chron
in this case, without any modification whereas xts represents all
times in POSIXct no matter what their original form was so as.xts
must map them all to POSIXct and in this conversion can introduce
small differences.

I can't reproduce this (see code below) but if you provide x1 in a
reproducible form then the above hypothesis can be double checked.

> Lines <- "07/23/09 15:13:00,19815,238
+ 07/23/09 15:14:00,19805,291
+ 07/23/09 15:15:00,19816,298
+ 07/23/09 15:16:00,19820,357
+ 07/23/09 15:17:00,19813,218
+ 07/23/09 15:18:00,19789,203"
>
> library(xts)
> library(chron)
> z <- read.zoo(textConnection(Lines), sep = ",", FUN = as.chron,
+ format = "%m/%d/%y %H:%M:%S")
> z
                       V2  V3
(07/23/09 15:13:00) 19815 238
(07/23/09 15:14:00) 19805 291
(07/23/09 15:15:00) 19816 298
(07/23/09 15:16:00) 19820 357
(07/23/09 15:17:00) 19813 218
(07/23/09 15:18:00) 19789 203
> as.xts(z)
                       V2  V3
(07/23/09 15:13:00) 19815 238
(07/23/09 15:14:00) 19805 291
(07/23/09 15:15:00) 19816 298
(07/23/09 15:16:00) 19820 357
(07/23/09 15:17:00) 19813 218
(07/23/09 15:18:00) 19789 203


On Thu, Jul 23, 2009 at 3:37 AM, Tseng Ko<ko.tseng at gmail.com> wrote:
> Dear all,
>
>  I tried to trasnform a zoo object to xts.
>
>> x1
>                        C   V
> (07/23/09 15:13:00) 19815 238
> (07/23/09 15:14:00) 19805 291
> (07/23/09 15:15:00) 19816 298
> (07/23/09 15:16:00) 19820 357
> (07/23/09 15:17:00) 19813 218
> (07/23/09 15:18:00) 19789 203
>
>> as.xts(x1)
>                        C   V
> (07/23/09 15:12:59) 19815 238
> (07/23/09 15:13:59) 19805 291
> (07/23/09 15:14:59) 19816 298
> (07/23/09 15:15:59) 19820 357
> (07/23/09 15:17:00) 19813 218
> (07/23/09 15:18:00) 19789 203
>
> Some data elements have 1 sec difference. Is it a bug in xts?
>
> Thanks.
>
> --
> Ko Tseng
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> 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