I have a data frame which contains two timestamps as in start and end as below I cant find the difference of these two but what I want is the difference between start of second row and end of first row. My data is
time_df <- data.frame(start=as.POSIXct(c('2020-08-23 07:40:59','2020-08-23 08:22:28','2020-08-23 08:54:46','2020-08-23 09:23:17','2020-08-24 07:39:10','2020-08-24 08:13:06','2020-09-01 10:21:04','2020-09-02 06:14:54','2020-09-02 07:44:59'))
,end=as.POSIXct(c('2020-08-23 08:15:23','2020-08-23 08:46:41','2020-08-23 09:17:05','2020-08-23 09:51:20','2020-08-24 08:09:29','2020-08-24 08:37:45','2020-09-01 10:56:41','2020-09-02 06:43:02','2020-09-02 08:08:50')))
What I am trying
time_df$duration <- as.numeric(difftime(time_df$end,time_df$start,units ="mins"))
but I want to find the difference between start of second row and end of first row keeping above data frame in min I want the difference of (8:22:28 - 8:15:23)