[datatable-help] POSIXct as data.table key

Ken Williams Ken.Williams at windlogics.com
Fri Sep 21 23:14:45 CEST 2012


Hi,

I see at https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1482&group_id=240&atid=978 that POSIXct values are supported as key.  But I'm unsure how to efficiently query them.  Here are my attempts:

> library(lubridate)
> n <- now()
> d <- data.table(t=n+days(1:10), val=runif(10), key='t')
> d[n+days(1)]
Error in `[.data.table`(d, n + days(1)) :
  i has not evaluated to logical, integer or double
> d[n+days(1),]
Error in `[.data.table`(d, n + days(1), ) :
  i has not evaluated to logical, integer or double
> d[list(n+days(1)),]
Error in `[.data.table`(d, list(n + days(1)), ) :
  typeof x.t (integer) != typeof i.V1 (double)


I can query using a boolean, but I assume this is skipping the index on 't'?

> d[t==n+days(1),]
                       t       val
[1,] 2012-09-22 21:06:52 0.2550606


Thanks.


--
Ken Williams, Senior Research Scientist
WindLogics
http://windlogics.com


________________________________
CONFIDENTIALITY NOTICE: This e-mail message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution of any kind is strictly prohibited. If you are not the intended recipient, please contact the sender via reply e-mail and destroy all copies of the original message. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120921/01e702c0/attachment.html>


More information about the datatable-help mailing list