R: A function to tell whether a single char is vowel or not

时光毁灭记忆、已成空白 提交于 2019-11-29 16:55:25

char=('a') or ('e') or ('i') or ('o') or ('u') is illegal. Try

isVowel <- function(char) char %in% c('a', 'e', 'i', 'o', 'u')

Let's try it:

isVowel('a')
# [1] TRUE
isVowel('b')
# [1] FALSE

Note that I did not use the or operator '||':

char == 'a' || char == 'e' || char == 'i' || char == 'o' || char == 'u'

as this is too long. I have used

char %in% c('a', 'e', 'i', 'o', 'u')

This will give TRUE if char is any of 'a', 'e', 'i', 'o', 'u'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!