How to count character set repetitions in a vector? Imagine the following vector consisting of "A" and "B" :
x <- c("A", "A", "A", "B", "B", "A", "A", "B", "A")
In this example, the first set is the sequence "A" and "B" from index 1 to 5, the second set is the sequence "A" and "B" from index 6 to 8, and then the third set is the last single "A" :
x <- c("A", "A", "A", "B", "B", # set 1 "A", "A", "B", # set 2 "A") # set 3
How to set up a counter for each set of variables? I need a vector like this:
c(1, 1, 1, 1, 1, 2, 2, 2, 3)
thanks
r
Christian
source share