title: R - Specifying a desired row order for the output data.frame of aggregate()
body: <p>I <code>aggregate()</code> the <code>value</code> column sums per <code>site</code> levels of the R data.frame given below:</p>
  
  <pre><code>set.seed(2013)
  df &lt;- data.frame(site = sample(c("A","B","C"), 10, replace = TRUE),
                   currency = sample(c("USD", "EUR", "GBP", "CNY", "CHF"),10, replace=TRUE, prob=c(10,6,5,6,0.5)),
                   value = sample(seq(1:10)/10,10,replace=FALSE))
  
  df.site.sums &lt;- aggregate(value ~ site, data=df, FUN=sum)
  df.site.sums
  
  #  site value
  #1    A   0.2
  #2    B   0.6
  #3    C   4.7
  </code></pre>
  
  <p>However, I would like to be able to specify the row order of the resulting <code>df.site.sums</code>. For instance like:  </p>
  
  <pre><code>reorder &lt;- c("C","B","A")
  ?special_sort(df, BY=site, ORDER=reorder) # imaginary function
  #  site value
  #1    C   4.7
  #2    B   0.6
  #3    A   0.2
  </code></pre>
  
  <p><strong>How can I do this using base R?</strong> Just to be clear, this is essentially a <em>data frame row ordering question</em> where the context is the <code>aggregate()</code> function (which may or may not matter). </p>
  
  <p><a href="https://stackoverflow.com/questions/11871464/aggregate-data-frame-while-keeping-original-order-in-a-simple-manner">This</a> is relevant but does not directly address my issue, or I am missing the crux of the solution.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>For future reference, I found a solution to ordering a data.frame's rows with respect to a target vector on this <a href="https://stackoverflow.com/questions/11977102/order-a-data-frames-rows-according-to-a-target-vector-that-specifies-the-desire?rq=1">link</a>. I guess it can be applied as a post-processing step.</p>
  
  <pre><code>df.site.sums[match(reorder,df.site.sums$site),]
  </code></pre>