title: Efficient way to create rank variables in R
body: <p>I would like to create several ranking variables in my data frame. First, I would like the best way to rank. </p>
  
  <p>Lets say I have data like this</p>
  
  <pre><code>grp&lt;-c("sw","sw","sw","sl","sl","sl","sw","sl")
  val&lt;-c(12,2,6,4,9,15,6,4)
  df&lt;-cbind.data.frame(grp,val)
  </code></pre>
  
  <p>I want the data ranked so that there are no breaks in rank, but with ties averaged. So like this: (I sorted the data using: df[order(df$val),] )</p>
  
  <pre><code>  grp val rk
  2  sw   2  1
  4  sl   4  2.5
  8  sl   4  2.5
  3  sw   6  3.5
  7  sw   6  3.5
  5  sl   9  4
  1  sw  12  5
  6  sl  15  6
  </code></pre>
  
  <p>I know how to get no breaks in order (by using dense_rank) and how to get ties averaged (using rank), but not how to get both. Dense rank does not appear to have any arguments that would let you specify what to do with ties. </p>
  
  <p>I would like something that I can apply easily to multiple columns if possible. </p>