79615468

Date: 2025-05-10 12:23:58
Score: 1
Natty:
Report link

As suggested by Tim, a cumsum of the event grouped by id is sufficient, in addition to replacing NA with 0s.

df %>% group_by(ID) %>% mutate(target=cumsum(replace_na(event, 0)))
Reasons:
  • Low length (1):
  • Has code block (-0.5):
  • Self-answer (0.5):
Posted by: Yacine Hajji