I’m unable to find a good solution, but I think there might be even a base or tidyverse R function that could do that:
My Data:
| Row | Label |
|---|---|
| 1 | NA |
| 2 | Foo |
| 3 | Foo |
| 4 | Foo |
| 5 | NA |
| 6 | NA |
| 7 | Foo |
| 8 | Foo |
| 9 | NA |
| 10 | Foo |
| 11 | NA |
| ... | ... |
What I want:
| Row | Label | FooCluster |
|---|---|---|
| 1 | NA | NA |
| 2 | Foo | 1 |
| 3 | Foo | 1 |
| 4 | Foo | 1 |
| 5 | NA | NA |
| 6 | NA | NA |
| 7 | Foo | 2 |
| 8 | Foo | 2 |
| 9 | NA | NA |
| 10 | Foo | 3 |
| 11 | NA | NA |
| ... | ... | ... |
Is there something elegant out there? Thanks for any help!