Let's assume I have the following sample data:
c(rep("A",6),rep("B",8),rep("A",3),rep("B",5),rep("A",9))
and I want to recode all the different groups of "A" and "B" as different groups, so whenever there is a change from "A" to "B" it means is a new group, in order to have this kind of output just to be clear:
c(rep("A",6),rep("B",8),rep("C",3),rep("D",5),rep("E",9))
I can easily do it with for loops, I am wondering if there is there a way to do it without using for loops, as I cannot think of a possible way with apply functions..
Thank you