I am trying to find common words having 5 unique vowels (i.e: "aeiuo" without in a single word and without repetition)
I tried this:
library(tidyverse)
x<-c("appropriate","associate","available","colleague","experience","encourage","encouragi","associetu")
x[str_count(x,"[aeiuo]")>4]
Note that words ("encouragi" and "associetu") were used for the purpose of verifying my intended answer
the results I am generating are the following:
[3] "available" "colleague"
[5] "experience" "encourage"
[7] "encouragi" "associetu"
While I wanted to get only:
"encouragi" "associetu"
which fulfill the criteria of having 5 distinct vowels (i.e: "aeiuo").
Is there any function to serve as string_count_unique?? if yes, which one? if not, what other function might you recommend me to use so that I meet the set criteria?
thank you in advance for your help!
One option could be:
x[lengths(lapply(str_extract_all(x, "a|e|i|u|o"), unique)) == 5]
[1] "encouragi" "associetu"
Maybe strsplit
could help you
> x[sapply(strsplit(x,""),function(v) sum(unique(v)%in%c("a","e","i","o","u"))>4) ]
[1] "encouragi" "associetu"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With