[datatable-help] How to do binary search on integer key?

Matthew Dowle mdowle at mdowle.plus.com
Fri Mar 8 09:10:40 CET 2013


I assume that 45 is a typo and should be 645.
All I can think is that you're using an architecture not covered by CRAN.
Only 32bit and 64bit on Unix, Mac or Windows is covered, not anything
else.
Please provide the output of :
   sessionInfo()
   test.data.table()
Also try again in fresh R session. After any slight memory corruption in
any package, strange things can happen.
Finally, do make sure to use the latest version of data.table (1.8.8) to
save us time in supporting you.  Only if what you said isn't true and in
fact the key column is double not integer, and, there are NA in it too can
I guess that the bug fixes in 1.8.8 would be in play.
Matthew

> I tried
>
> table[list(645)]
>
> table[.(645)]
>
> table[J(45)]
>
> they're all returning 78 records when in fact there should only be 18
> records related to key 645. However if I use table[id==645,], I get the
> right result.
>
> On Fri, Mar 8, 2013 at 12:42 AM, Michael Nelson <
> michael.nelson at sydney.edu.au> wrote:
>
>>  you just need to wrap the values in `list()` or  `.()
>>
>>
>>  eg
>>
>>  table[list(645)]
>>
>>  table[.(645)]
>>  ------------------------------
>> *From:* datatable-help-bounces at lists.r-forge.r-project.org [
>> datatable-help-bounces at lists.r-forge.r-project.org] on behalf of Yi Yuan
>> [
>> lambandme at gmail.com]
>> *Sent:* Friday, 8 March 2013 4:25 PM
>> *To:* datatable-help at lists.r-forge.r-project.org
>> *Subject:* [datatable-help] How to do binary search on integer key?
>>
>>   Hi, all:
>> I know someone has asked exactly the same question and there's even an
>> answer. But I think the answer is wrong. Following is the url of that
>> question
>> http://r.789695.n4.nabble.com/Binary-search-with-integer-key-td3705686.html
>>
>>  so if the key is integer and I would like to select all records where
>> the key=654, how do I do that?
>>  suppose the data table is named table, key variable's name is id
>>
>>  I know you can do it by writing: table[id==645,], but R will conduct
>> vector search this way and is a lot slower than binary search.
>>
>>  So how can I do binary search on integer key??
>>
>>  Thanks!!
>>
> _______________________________________________
> 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