I have a dataframe with a column that represents the beginning (1) and the end (2) of an event. The duration of the event is the number of zeros between 1 and 2. This event may occur multiple times. The column looks like this:
event <- c(1002, 100000000000000000, 10002000102000, 10000, 100000210200000000, 10020000010200000)
I have tried stringr::str_count(string = event, pattern = "0"), but of course, that gives me the total number of zeros. What i need is the number of zeros between first 1, then 2. Zeros after a 2 should be dropped.
2
17
3 1
4
5 1
2 1
I can't figure out how to do this, it could be that my approach here is all wrong. Can anyone give me some direction?