title: R: Sort multiple columns by another data.frame?
body: <p>I'm trying to make sense of how to sort one data.frame based on multiple columns in another.  This question <a href="https://stackoverflow.com/questions/1568511/how-do-i-sort-one-vector-based-on-values-of-another">does this with vectors</a>.  Can someone suggest a way to do the equivalent with data.frames?</p>
  
  <p>Here's some sample data.</p>
  
  <pre><code>x1 &lt;- data.frame(a=1:5, b=letters[1:5], c=rnorm(5))
  x2 &lt;- data.frame(a=c(4,4,2), b=c("d", "d", "b"), d=rnorm(3))
  </code></pre>
  
  <p>So I want to sort x2 by the first two columns of x1.  My actual data is much more complicated, but this replicates the idea...</p>