title: Rank by two columns and keep ties
body: <p>My question is continuation of this probem <a href="https://stackoverflow.com/questions/3197999/how-i-can-create-a-new-ties-method-with-the-r-rank-function">Link</a></p>
  
  <p>I have a dataset such as this one: </p>
  
  <pre><code> ID    |     Date 
  
    A        01/01/2015
    A        02/01/2015
    A        02/01/2015
    A        02/01/2015
    A        05/01/2015     
    B        01/01/2015
  </code></pre>
  
  <p>I want to rank each date by a referential date - 31/01/2015. The closest date to the referential date being ranked 1, second 2, and so on.  The result would look like: </p>
  
  <pre><code>  ID    |     Date           |  Sequence
  
    A        01/01/2015           3
    A        02/01/2015           2
    A        02/01/2015           2
    A        02/01/2015           2
    A        05/01/2015           1  
    B        01/01/2015          ...
  </code></pre>
  
  <p>While the rank function does think, I also want to keep all the ties. How do I do that? </p>
  
  <p>Also, I am working with a huge dataset - approx. 300 million rows. So the solution would ideally be fast. </p>