Removing duplicate row items

I have a string: string <- "YYYYYXXXYYXZYYZ"and I want to keep only one copy of repetitive elements, so the line would read as follows: "YXYXZYZ". What is the best way to do this ??

+4
source share
1 answer

This is with gsub:

gsub('([[:alpha:]])\\1+', '\\1', string)

From another answer fom @Yihui Xie at How to remove duplicate characters in a string using R?

+1
source

Source: https://habr.com/ru/post/1695820/


All Articles