Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

milliseconds timestamps as keys in data.table

In this question the issue of using dates in data.tables was discussed. A solution is to use the built-in classes for time and dates. These work with a precision up to the second. Is there a work-around to handle milliseconds in indexed columns?

like image 432
Ryogi Avatar asked Oct 25 '11 22:10

Ryogi


2 Answers

The built-in class for Dates and Times, eg POSIXct works to milliseconds (windows) and microseconds (Linux, OS X). You probably haven't turned on the option to have subseconds printed:

R> Sys.time()                            ## under default options
[1] "2011-10-25 17:40:05 CDT"
R> options("digits.secs"=7)              ## you may want this in ~/.Rprofile too
R> Sys.time()
[1] "2011-10-25 17:40:11.177271 CDT"     
R> 
like image 132
Dirk Eddelbuettel Avatar answered Nov 13 '22 07:11

Dirk Eddelbuettel


Yeah, data.table requires keys to be integers or similar (i.e. POSIXct rounded to seconds). I would work-around this by storing 1000 * timestamp as your key, and perhaps having a separate column which is the non-rounded POSIXct. Or you can convert to POSIXct on the fly whenever you need it.

like image 35
Muhammad Waliji Avatar answered Nov 13 '22 08:11

Muhammad Waliji