Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find words with at most two vowels

I have made a function to search words which have two vowels together. The function give me the vowels together (for example: ee, ou), but I need the complete word (tree, four).

lt <- c("tree", "four", "hello", "play")

vowel <- function(x) {  
  a<- regexpr(pattern = "[aeiou]{2}", x) 
    regmatches(x, a)
}

vowel(lt)

# [1] "ee" "ou"

Thank you in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

We can simply use grepl which in my opinion is more user friendly.

vowel <- function(x) 
   
 {  
   a<- grepl("[aeiou]{2}", x) 
   x[a]
 }
 vowel(lt)
[1] "tree" "four"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading