r - Removing repeated letters/alphabets -


input : kdff455556tfkkkw

output1 : kdf[2]45[4]6tfk[3]w

hint: repeated "alphnum" alphnum[no_of_repetition]

s <- c('kdff455556tfkkkw','abc','abbccc'); sapply(strsplit(s,''),function(x) paste(with(rle(x),ifelse(lengths==1,values,paste0(values,'[',lengths,']'))),collapse='')); ## [1] "kdf[2]45[4]6tfk[3]w" "abc"                 "ab[2]c[3]" 

Comments

Popular posts from this blog

html - height not adding height to a empty div -

angularjs - Redirect to a new template in angular js -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -