Calculating differences of dates in hours between rows of a dataframe
问题 I have the following dataframe (ts1): D1 Diff 1 20/11/2014 16:00 0.00 2 20/11/2014 17:00 0.01 3 20/11/2014 19:00 0.03 I would like to add a new column to ts1 that will be the difference in hours between successive rows D1 (dates) in hours. The new ts1 should be: D1 Diff N 1 20/11/2014 16:00 0.00 2 20/11/2014 17:00 0.01 1 3 20/11/2014 19:00 0.03 2 For calculating the difference in hours independently I use: library(lubridate) difftime(dmy_hm("29/12/2014 11:00"), dmy_hm("29/12/2014 9:00"),