title: How to efficiently compute difftime in a map by ID
body: <p>Given the following data :</p>
  
  <pre><code>       cdate    cid cprice
  1  2013-05-24 **275059**  74.99
  2  2013-04-15 **275059**  63.10
  3  2013-03-12 **275059**  40.39
  4  2013-09-03 276620  62.09
  5  2013-03-27 276261  34.11
  6  2012-12-20 276136  60.96
  7  2013-01-25 276136  69.96
  8  2012-11-23 276136 105.17
  9  2012-11-09 276136  73.20
  10 2013-01-09 276136  73.40
  </code></pre>
  
  <p>I want to efficiently compute (got more than 2 millions rows) the difference (in days), for each clients (cid column) of his last purchase date with the current daytime.</p>
  
  <p>Something like :</p>
  
  <pre><code>getrecense &lt;- function(f){ return(as.integer(difftime(format(Sys.Date(),"%Y-%m-%d"), max(f$cdate)))); }
  recence &lt;- data.frame(as.table(by(clients, clients$cid, getrecence)));
  </code></pre>
  
  <p>do exactly what I want, but not scalable at all.</p>