Checking if string is in uppercase in R

…衆ロ難τιáo~ 提交于 2019-12-03 22:32:12

You can use the ^ and $ patterns to match the beginning and end of the string

grepl("^[[:upper:]]+$", s)
Michael Kelly

Why not just test if the word is identical to itself when converted to upper case with the "toupper" function?

word1 <- "TEST"
word1 == toupper(word1) 

will be TRUE

If you prefer to live in a tidyr universe, here's the version using stringr:

library(stringr)
str_detect(s, "^[:upper:]+$")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!