title: Group and Calculate number of days between (first and second) and (first and third) occurred an id inR
body: <p>how can i group and calculate number of days between (first and second) and (first and third) occurred an id in R,
  for example i have below dataframe:</p>
  
  <pre><code>CRASH_DATE  geoid           CRASH_TIME  type
  2015-12-10  123             1650        Fatal_i
  2015-12-06  156             1722        Fatal_i
  2015-12-10  123             1956        Fatal_i
  2015-11-29  156             705         Fatal_i
  2015-11-21  156             1756        Fatal_i
  2015-12-10  123             1936        Fatal_i
  2015-11-19  156             712         Fatal_i
  2015-11-21  112             1706        Fatal_i
  ...
  </code></pre>
  
  <p>i want an output such as:</p>
  
  <pre><code>geoid   days_between(1,2)    days_between(1,3)
  123     0                    0                 
  156     2                    10                
  112     Nan                  Nan                       
  ...
  </code></pre>
  
  <p>and this is my code:</p>
  
  <pre><code> dt2  &lt;- data.table(table)
   dt22 &lt;- dt2[,list(diff1 = CRASH_DATE - shift(CRASH_TIME, fill = 
   first(CRASH_TIME)),diff2 = CRASH_DATE - shift(CRASH_TIME, fill = 
   first(CRASH_TIME))),by = c("geoid")]
  </code></pre>
  
  <p>but it is wrong.</p>