I want to find the unique sequences in my vector. A sequence is a series of identical values. If a sequence repeats, it counts as two sequences, as long as there is another sequence in between. A sequence can have a length of one value.
So that if my function is called findSequences(), it would work like this:
my_vector = c('a', 'a', 'b', 'a', 'c', 'c', 'b')
find_Sequences(my_vector)
> 'a', 'b', 'a', 'c', 'b'
unique() and distinct() don't do this.
You can use rle
.
rle(my_vector)$values
#[1] "a" "b" "a" "c" "b"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With