I have data where consecutive runs of zero are separated by runs of non-zero values. I want to create a counter for the runs of zero in the column \'SOG\'.
For the fi
Try
df$stops<- with(df, cumsum(c(0, diff(!SOG))>0)*!SOG) df$stops # [1] 0 0 1 1 1 0 0 0 2 2 0 0 3 3 3