I have a vector of the type
c(3,3,...,9,9,...,2,2,...,3,3,...,7,7,...)
I want to remove the repeated numbers in a sequence, without breaking the order. This is, I would like to obtain something like
c(3,9,2,3,7,...)
How can I do this in R?
We can also use the observation that a duplicate in sequence has a difference of 0 with their neighbour. Therefore, using base-R, we can do:
v[c(1,diff(v))!=0]
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