This is a subset of my data
# | Event | Time
1 A 22:00:00
2 B 22:00:10
3 B 22:00:20
4 B 22:00:30
5 C 22:00:40
6 B 22:00:10
7 B 22:00:20
8 B 22:00:30
9 A 22:00:40
I want to calculate the duration of a continuous occurrence of a same event – so, say I want the duration of event B, the output should be
# | Event | Time | Duration
1 A 22:00:00 NA
2 B 22:00:10 20 Secs
3 B 22:00:20 NA
4 B 22:00:30 NA
5 C 22:00:40 NA
6 B 22:00:10 20 Secs
7 B 22:00:20 NA
8 B 22:00:30 NA
9 A 22:00:40 NA
I've tried (variations of) solutions from: Using conditional statements with difftime in R and Calulcate running difference of time using difftime on one column of timestamps
But I can't seem to get what I'm trying to achieve. Hope I can get some help! Thanks!