Skip to content
Prev 10570 / 15274 Next

xts and Sys.time() - very stange behaviour

On Wed, Aug 1, 2012 at 1:57 PM, Brian G. Peterson <brian at braverock.com> wrote:
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...

Jeff