title: ordering character vector in R by chosen target order
body: <p>I have a dataframe with a names column, these names are repeated (same people have multiple row entries). I would like to order the data frame based on an order of my choosing. For example, here is a simplified version of the problem:</p>
  
  <pre><code>df &lt;- data.frame(index = rep(1, 12), name = sample( LETTERS[1:3], 12, replace = TRUE) )
  target &lt;- c( 'C', 'A', 'B' )
  </code></pre>
  
  <p>so what i want is to order <code>df</code> so that all the rows with 'C' are first, followed by the 'A' rows then the 'B' rows.</p>
  
  <p>One way to do it is to subset the dataframe into the seperate cases, then use <code>rbind</code>, which works, but this doesn't seem efficient for large dataframes with many different names</p>