There is a problem that I do not know how to solve.
You need to write a function that returns all words from a string that contain repeated letters and the maximum number of their repetitions in a word.
Visually, this stage can be viewed with the following example:
"hello good home aboba" after processing should be hello good, and the maximum number of repetitions of a character in a given string = 2.
The code I wrote from tries to find duplicate characters and based on this, extract words from a separate array, but something doesn't work. Help solve the problem.
library(tidyverse)
library(stringr)
text = 'tessst gfvdsvs bbbddsa daxz'
text = strsplit(text, ' ')
text
new = c()
new_2 = c()
for (i in text){
new = str_extract_all(i, '([[:alpha:]])\\1+')
if (new != character(0)){
new_2 = c(new_2, i)
}
}
new
new_2
Output:
Error in if (new != character(0)) { : argument is of length zero
> new
[[1]]
[1] "sss"
[[2]]
character(0)
[[3]]
[1] "bbb" "dd"
[[4]]
character(0)
> new_2
NULL