How to subtract datetimes and store them in a separate column?
<p>i am working with csv file and i have a column with name "statistics_lastLocatedTime" as shown in
<a href="https://i.stack.imgur.com/toUju.png" rel="nofollow noreferrer">csv file image</a>
i would like to subtract second row of "statistics_lastLocatedTime" from first row; third row from second row and so on till the last row and then store all these differences in a separate column and then combine this column to the other related columns as shown in the code given below:</p>

<pre><code>##select related features
data &lt;- read.csv("D:/smart tech/store/2016-10-11.csv")
(columns &lt;- data[with(data, macAddress == "7c:11:be:ce:df:1d" ),
    c(2,10,11,38,39,48,50) ])
write.csv(columns, file = "updated.csv", row.names = FALSE)

## take time difference 
date_data &lt;- read.csv("D:/R/data/updated.csv")
(dates &lt;- date_data[1:40, c(2)])
NROW(dates)
for (i in 1:NROW(dates)) {
  j &lt;- i+1
  r1 &lt;- strptime(paste(dates[i]),"%Y-%m-%d %H:%M:%S")
  r2 &lt;- strptime(paste(dates[j]),"%Y-%m-%d %H:%M:%S")
  diff &lt;- as.numeric(difftime(r1,r2))
  print (diff)
}

## combine time difference with other related columns
combine &lt;- cbind(columns, diff)
combine
</code></pre>

<p>now the problem is that i am able to get the difference of rows but not able to store these values as a column and then combine that column with other related columns. please help me. thanks in advance.</p>