title: R: set order of data table by col of a different data table?
body: <p>I've seen examples of sorting a data table by one of its columns, but how do I sort a data table by the column of a different data table? For example if I have two data tables:</p>
  
  <pre><code>x &lt;- data.table(ID=1:3,A=letters[3:1])
  y &lt;- data.table(ID=1:3,B=letters[1:3])
  </code></pre>
  
  <p>I want to sort <code>x</code> based on the order of <code>y$B</code>:</p>
  
  <pre><code>setorder(x,y$B)
  Error in setorderv(x, cols, order, na.last) : 
    some columns are not in the data.table: $,y,B
  </code></pre>
  
  <p>How do I reference a col in <code>y</code> when sorting <code>x</code>?</p>