title: Calculating elapsed time between samples in R
body: <p>I have a very large database and I need to calculate Elapsed time between samples and put results into another column so that I can later do duration caculations... </p>
  
  <p>I have been able to mostly do this but my results aren't quite right... </p>
  
  <pre><code>    station$datetime&lt;-as.POSIXct(paste(station$ï..SAMPLE_DATE,station$SampleTime), format="%Y-%m-%d %H:%M:%S")
  
      storder&lt;-station[order(station$datetime),]  
  
      storder$timeel &lt;- storder$datetime - storder$datetime[1]
  </code></pre>
  
  <p>This code works to combine and format my datetime and put in order and it does give me results of elapsed time... sorta.... </p>
  
  <pre><code>&gt; head(storder$datetime)
  [1] "2005-06-01 09:00:01 EDT" "2005-06-01 09:15:01 EDT" "2005-06-01 09:30:01 EDT" "2005-06-01 09:45:01 EDT"
  [5] "2005-06-01 10:00:01 EDT" "2005-06-01 10:15:01 EDT"
  &gt; head(storder$timeel)
  Time differences in secs
  [1]    0  900 1800 2700 3600 4500
  </code></pre>
  
  <p>SO my question is....  How do I get it to not be cumulative?</p>
  
  <p>What I need is more along the line of 0  900  900  901  900  903 ect.... (and eventually I'll convert to minutes)</p>
  
  <p>I've been looking but I'm sure I've missed something simple... again... </p>