title: Using the `difftime` function within the lubridate package in R to find consecutive differences in a vector of dates?
body: <p>I currently have a vector of dates called <code>dates</code> which have been taken in using the ymd_hms function.</p>
  
  <pre><code>dates &lt;- c("2013-09-01 23:05:24", "2013-09-02 22:51:09", "2013-09-04 00:09:16", "2013-09-04 23:43:31", "2013-09-06 00:17:41", "2013-09-06 22:42:27", "2013-09-08 00:22:27")
  
  ymd_hms(dates)
  </code></pre>
  
  <p>I am trying to find the consecutive differences between the dates, the easiest function of which to use is <code>difftime</code>. Is there a function or apply function I can use in R to do this that is fast? While the above can be very easy as it is short, I am trying to come up with a solution that can take care of millions of millions of rows. </p>
  
  <p>Normally I'd just do:</p>
  
  <pre><code>as.numeric(diff(event_date)))
  </code></pre>
  
  <p>but I need the day, seconds, etc specification in difftime. </p>
  
  <p>Thanks!</p>