[datatable-help] POSIXct as data.table key
Matthew Dowle
mdowle at mdowle.plus.com
Sat Sep 22 10:48:12 CEST 2012
Welcome.
No time right now to test, so just quick reply...
This is the correct form (that you correctly tried) :
d[list(n+days(1)),]
or you can use these (all identical) :
d[list(n+days(1))] # comma is optional
d[J(n+days(1))]
d[.(n+days(1))]
I don't know libridate, but I guess the reason for :
> Error in `[.data.table`(d, list(n + days(1)), ) :
> typeof x.t (integer) != typeof i.V1 (double)
might be, try
d[J(n+days(1L))]
instead of
d[J(n+days(1))]
> I can query using a boolean, but I assume this is skipping the index on
> 't'?
Yes, exactly.
> 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.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
More information about the datatable-help
mailing list