i want to find the cumulative count before there is a change in value, i.e. how many rows since the last change. For illustration:
| Value | diff | #row since last change (how do I create this column?) |
|---|---|---|
| 6 | na | na |
| 5 | -1 | 0 |
| 5 | 0 | 1 |
| 5 | 0 | 2 |
| 4 | -1 | 0 |
| 4 | 0 | 1 |
| 4 | 0 | 2 |
| 4 | 0 | 3 |
| 4 | 0 | 4 |
| 5 | 1 | 0 |
| 5 | 0 | 1 |
| 5 | 0 | 2 |
| 5 | 0 | 3 |
| 6 | 1 | 0 |
| 7 | 1 | 0 |
i tried to use cumsum but it does not reset after each change