I am looking to create a variable that increments when specific strings appear in a column. If strings "x", "y", or "z" appear in Event, I want the sequence to increment, otherwise I would like it to stay constant. Any help would be appreciated! See table below:
Event Seq
1 a 1
2 b 1
3 x 2
4 c 2
5 a 2
6 b 2
7 y 3
8 a 3
9 z 4
10 b 4
11 y 5
12 a 5
13 b 5
ave(df$Event %in% c("x", "y", "z"), TRUE, FUN = cumsum)
cumsum(df$Event %in% c("x", "y", "z"))
would work