title: Adding a ranking column to a dataframe
body: <p>This seems like it must be a very common task, but I can't find a solution in google or SO. I want to add a column called 'rank' to 'dat1' based on the sequence that 'order.scores' applies to 'dat'. I tried using row.names(), but the rownames are based on 'dat', not 'dat1'. I also tried 'dat$rank &lt;-rank(dat1)', but this produces an error message. </p>
  
  <pre><code>fname&lt;-c("Joe", "Bob", "Bill", "Tom", "Sue","Sam","Jane","Ruby")
  score&lt;-c(500, 490, 500, 750, 550, 500, 210, 320)
  dat&lt;-data.frame(fname,score)
  order.scores&lt;-order(dat$score,dat$fname)
  dat1&lt;-dat[order.scores,]
  </code></pre>