Skip to content

Instantly share code, notes, and snippets.

@lornamariak
Created October 11, 2017 12:57
Show Gist options
  • Save lornamariak/0311e2e14b8d29f69ba534da80767fc3 to your computer and use it in GitHub Desktop.
Save lornamariak/0311e2e14b8d29f69ba534da80767fc3 to your computer and use it in GitHub Desktop.
COUNTING NUMBER OF VOWELS IN A SENTENCE
x <- readline(prompt = "Enter Sentence: " ) # Ask user to enter word or sentence
#split the sentence into characters and store them as list
sentence = as.list(strsplit(x, "" )[[1]])
vowels = list("a","e","i","o","u") # store vowels as a list
# check for vowels in the sentence and print TRUE for every vowel found
print( vowels %in% sentence )
# print the letters that appear in the vowel list and sentence list
print((intersect(vowels,sentence)))
# print the length of the string in line 8 which is the number of vowels present
print(length((intersect(vowels,sentence))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment