I tried <div><span style="font-family:Tahoma;font-size:13px"><br></span></div><div><span style="font-family:Tahoma;font-size:13px">table[list(645)]</span><div style="font-family:Tahoma;font-size:13px"><br></div><div style="font-family:Tahoma;font-size:13px">
table[.(645)]</div><div style="font-family:Tahoma;font-size:13px"><br></div><div style="font-family:Tahoma;font-size:13px">table[J(45)]</div><div style="font-family:Tahoma;font-size:13px"><br></div><div style="font-family:Tahoma;font-size:13px">
they're all returning 78 records when in fact there should only be 18 records related to key 645. However if I use <span style="color:rgb(34,34,34);font-family:arial,sans-serif">table[id==645,], I get the right result.</span></div>
<br><div class="gmail_quote">On Fri, Mar 8, 2013 at 12:42 AM, Michael Nelson <span dir="ltr"><<a href="mailto:michael.nelson@sydney.edu.au" target="_blank">michael.nelson@sydney.edu.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div style="direction:ltr;font-size:10pt;font-family:Tahoma">you just need to wrap the values in `list()` or `.()
<div><br>
</div>
<div><br>
</div>
<div>eg </div>
<div><br>
</div>
<div>table[list(645)]</div>
<div><br>
</div>
<div>table[.(645)]<br>
<div style="font-size:16px;font-family:Times New Roman">
<hr>
<div style="direction:ltr"><font face="Tahoma" color="#000000"><b>From:</b> <a href="mailto:datatable-help-bounces@lists.r-forge.r-project.org" target="_blank">datatable-help-bounces@lists.r-forge.r-project.org</a> [<a href="mailto:datatable-help-bounces@lists.r-forge.r-project.org" target="_blank">datatable-help-bounces@lists.r-forge.r-project.org</a>] on behalf of Yi Yuan [<a href="mailto:lambandme@gmail.com" target="_blank">lambandme@gmail.com</a>]<br>
<b>Sent:</b> Friday, 8 March 2013 4:25 PM<br>
<b>To:</b> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><br>
<b>Subject:</b> [datatable-help] How to do binary search on integer key?<br>
</font><br>
</div><div><div class="h5">
<div></div>
<div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
Hi, all:</div>
<span style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">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</span>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<a href="http://r.789695.n4.nabble.com/Binary-search-with-integer-key-td3705686.html" style="color:rgb(17,85,204)" target="_blank">http://r.789695.n4.nabble.com/Binary-search-with-integer-key-td3705686.html</a></div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br>
</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
so if the key is integer and I would like to select all records where the key=654, how do I do that?</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
suppose the data table is named table, key variable's name is id</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br>
</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
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.</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br>
</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
So how can I do binary search on integer key??</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
<br>
</div>
<div style="color:rgb(34,34,34);font-size:13px;font-family:arial,sans-serif">
Thanks!!</div>
</div>
</div></div></div>
</div>
</div>
</div>
</blockquote></div><br></div>