Here is a toy data.
datetime <- c('2019-11-06 13:05:07',
'2019-11-06 13:05:08',
'2019-11-06 13:05:09',
'2019-11-06 13:05:10',
'2019-11-06 13:05:11',
'2019-11-06 13:05:12',
'2019-11-06 13:05:13',
'2019-11-06 13:05:14',
'2019-11-06 13:05:15',
'2019-11-06 13:05:16',
'2019-11-06 13:05:17',
'2019-11-06 13:05:18',
'2019-11-06 13:05:19',
'2019-11-06 13:05:20',
'2019-11-06 13:05:21',
'2019-11-06 13:05:22')
active <- c(1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0)
df <- data.frame(datetime, active)
I am looking for a vectorize code that will compute the activity blocks. In the above example we have 2 activity blocks.
- 13:05:07 - 13:05:10
- 13:05:16 - 13:05:20