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 ??
string <- "YYYYYXXXYYXZYYZ"
"YXYXZYZ"
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?
Source: https://habr.com/ru/post/1695820/More articles:getDerivedStateFromProps not called - reactjsHow to use devtools :: use_data in a list of data frames? - rHeat map when color is scaled - rHow to bind member functions in a PL / SQL object - functionR Date Ranges of time data per hour Duration sum - datetimeDivide the data table by the hourly totals in R - rГитарные аккорды пользовательский тег простой парсер - javascriptHTTP-запрос с Oauth2 в приложение Google Script Веб-приложение - c#Python 3.6 dynamic dictionary dynamic update - pythonGet a DNS name called Programmatically - kubernetesAll Articles