Yesterday I have asked similar question Count each next occurence of string in substring now I'm struggling with another one:
apple.a > banana.b > banana.b > carrot-c > banana.b > apple.a > carrot-c > banana.b > apple.a
What I want to achieve, is to check consecutive occurences, so the result would be
apple.a1 > banana.b1 > banana.b2 > carrot-c1 > banana.b1 > apple.a1 > carrot-c1 > banana.b1 > apple.a1
I have already tried several solutions:
Count consecutive TRUE values within each block separately
Counting the number of occurrences of a value in R
R: count consecutive occurrences of values in a single column
to list few of them, but none seem to have worked for me and I couldn't achieve desired results. I tried to combine strsplit
with unlist
, sequence
, rle
and several other functions and wasn't able to overcome my problem.
To clear things up: data frame has several columns and sequence of words is stored in one of them.