title: Subsetting a data.table by range making use of binary search
body: <p>How do you go about subsetting a data.table by a numeric range, with the intention of using binary search? </p>
  
  <p>For example:</p>
  
  <pre><code>require(data.table)
  set.seed(1)
  
  x&lt;-runif(10000000,min=0,max=10)
  y&lt;-runif(10000000,min=0,max=10)
  
  DF&lt;-data.frame(x,y)
  DT&lt;-data.table(x,y)
  
  system.time(DFsub&lt;-DF[DF$x&gt;5 &amp; DF$y&lt;7,])
  # user  system elapsed 
  # 1.529   0.250   1.821 
  
  #subset DT
  system.time(DTsub&lt;-DT[x&gt;5 &amp; y&lt;7])
  # user  system elapsed 
  #0.716   0.119   0.841 
  </code></pre>
  
  <p>The above doesn't use a key (vector scan), and the speed-up isn't so dramatic. What is the syntax for subsetting a numeric range of a data.table, making use of binary search?
  I can't find a good example in the documentation; it would be helpful if someone could provide an example using the toy data.table above.</p>
  
  <p>EDIT: This question is similar, but still doesn't demonstrate how to subset by a range:
  <a href="https://stackoverflow.com/questions/20720161/data-table-vector-scan-v-binary-search-with-numeric-columns-super-slow-setkey?rq=1">data.table: vector scan v binary search with numeric columns - super-slow setkey</a></p>