<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">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-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF356516" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> datatable-help-bounces@lists.r-forge.r-project.org [datatable-help-bounces@lists.r-forge.r-project.org] on behalf of Yi Yuan [lambandme@gmail.com]<br>
<b>Sent:</b> Friday, 8 March 2013 4:25 PM<br>
<b>To:</b> datatable-help@lists.r-forge.r-project.org<br>
<b>Subject:</b> [datatable-help] How to do binary search on integer key?<br>
</font><br>
</div>
<div></div>
<div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
Hi, all:</div>
<span style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">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-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
<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-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
<br>
</div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
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-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
suppose the data table is named table, key variable's name is id</div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
<br>
</div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
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-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
<br>
</div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
So how can I do binary search on integer key??</div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
<br>
</div>
<div style="color:rgb(34,34,34); font-family:arial,sans-serif; font-size:13px; background-color:rgb(255,255,255)">
Thanks!!</div>
</div>
</div>
</div>
</div>
</body>
</html>