I have a data frame that looks as follows:
| ID# | Days Since Activity |
|---|---|
| 1 | 1 |
| 1 | 5 |
| 1 | 5 |
| 1 | 10 |
| 1 | 3 |
| 2 | 4 |
| 2 | 2 |
| 2 | 9 |
And I want to include a "count" column that counts all entries and resets when the ID# changes OR if the "Days Since Activity" is 10 or greater. An example output is as follows:
| ID# | Days Since Activity | Count |
|---|---|---|
| 1 | 1 | 1 |
| 1 | 5 | 2 |
| 1 | 5 | 3 |
| 1 | 10 | 1 |
| 1 | 3 | 2 |
| 2 | 4 | 1 |
| 2 | 2 | 2 |
| 2 | 9 | 3 |
I tried doing the following code:
df <- df %>%
group_by(`ID#`) %>%
mutate(`Count` = seq(n()))
But that only reset the count when the ID# changed. How can I incorporate both criteria into my count? Thank you!!