Assume that I have this data set
I would like this result
I am not sure how to do this, but here is my pseudocode
problem = if_else(problem == 0, 0, sum of all previous 1s)
I have tried
dataset <- dataset %>% mutate(problem = if_else(problem == 0, 0, problem + lag(problem))
That will only get me a 2 as the highest number. How would I accomplish this. Also, the column name for the total could be different from problem as well.