Let's say we want to eliminate duplicated subsequence element from a string (it can be more than one). For example:
2,14,14,14,19
and convert it into:
2,14,19
Using gsub, we can achieve it:
gsub("(\\d+)(,\\1)+","\\1", "2,14,14,14,19")
[1] "2,14,19"
...