[R-SIG-Finance] xts and Sys.time() - very stange behaviour

Daniel Cegiełka daniel.cegielka at gmail.com
Wed Aug 1 22:22:50 CEST 2012


> Note that this isn't likely the cause, unless you are concurrently
> doing something like as.character(index(x))=="2001-01-01 08:30:01.999"
> with an xts object.  That will convert the internal representation of
> the _entire_ index from double to "time", whatever class that may be,
> and then to character!.
>
> If you use xts subsetting itself, the 'character' turns into a POSIXct
> for the value you are trying to match against.  So you only incur
> _one_ conversion (instantaneous).  This numeric value is then search
> for via binary search (i.e. O(log n) cost - more or less).  For
> anything like tick data, binary search is going to be much faster than
> a linear scan.
>
> Anyway, all the above still fails you if you catch a floating point
> issue.  I've got some ideas (no code) on a better way to do this of
> course...

Interesting discussion. This can be solved by using a uint64_t for the
timestamp index (date+time) - fast binary search would be still
available. Package providing int64 types in R:

http://cran.r-project.org/web/packages/int64/index.html

Daniel



More information about the R-SIG-Finance mailing list