I'm working with accelerometer data (the SB column) and would like to add a variable that counts the length of an activity bout e.g. sitting(SB), and restarts counting after the person got up ("SB_count"). In a second step, I would like to create a 2nd variable ("SB_bout" which only keeps the final bout length values.
I've been stuck on this for a while, probably because I was using the wrong search terms, so I would really appreaciate it, if someone could point me in the right direction.
This is what it should look like:
      SB      SB_count  SB_bout
1     1       1         0
2     1       2         0
3     1       3         3
4     0       0         0
5     1       1         0
6     1       2         2
 
     
    