title: Get the time between consecutive dates stored in a single column
body: <p>I am trying to figure out how to get the time between consecutive events when events are stored as a column of dates in a dataframe.</p>
  
  <pre><code>sampledf=structure(list(cust = c(1L, 1L, 1L, 1L), date = structure(c(9862, 
  9879, 10075, 10207), class = "Date")), .Names = c("cust", "date"
  ), row.names = c(NA, -4L), class = "data.frame")
  </code></pre>
  
  <p>I can get an answer with</p>
  
  <pre><code>as.numeric(rev(rev(difftime(c(sampledf$date[-1],0),sampledf$date))[-1]))
  # [1]  17 196 132
  </code></pre>
  
  <p>but it is really ugly.  Among other things, I only know how to exclude the first item in a vector, but not the last so I have to rev() twice to drop the last value.</p>
  
  <p>Is there a better way?</p>
  
  <p>By the way, I will use ddply to do this to a larger set of data for each cust id, so the solution would need to work with ddply.</p>
  
  <pre><code>library(plyr)
  ddply(sampledf, 
                c("cust"), 
                summarize,
                daysBetween = as.numeric(rev(rev(difftime(c(date[-1],0),date))[-1]))
  )
  </code></pre>
  
  <p>Thank you!</p>