Suppose we have this tibble:
group item
x 1
x 2
x 2
y 3
z 2
x 2
x 2
z 1
I want to perform a group_by by group. However, I'd rather group only by the elements that are adjacent. For example, in my case, I'd have three 'x' groups, summing 'item' elements. The result would be something like:
group item
x 5
y 3
z 2
x 4
z 1
I know how to solve this problem using 'for' loops. However, this is not fast and doesn't sound straightforward. I'd rather use some dplyr or tidyverse function with an easy logic.
This question is not duplicated. I know there's already a question about rle in SO, but my question was more general than that. I asked for general solutions.