title: Most efficient way to sort two vectors in lockstep in R?
body: <p>What's the most efficient way to sort two vectors in lockstep in R?  The first vector should be sorted in ascending order and the second should be reordered in lockstep such that elements with corresponding indices before the sort still have corresponding indices after the sort.  For example:</p>
  
  <pre><code>foo &lt;- c(1,3,2, 5,4)
  bar &lt;- c(2,6,4,10,8)
  sort2(foo, bar)
  
  # foo == c(1,2,3,4, 5)
  # bar == c(2,4,6,8,10)
  </code></pre>
  
  <p>Note:  Efficiency is an absolute must here as I am trying to use this as the basis for creating an O(N log N) implementation of Kendall's Tau to submit as a patch.  I'd like to avoid writing my own special function in C to do this, but would be willing to if it can't be done efficiently within R.</p>