大写字母字符串r



我有一个字符向量,其中一些单词以小写字母开头,一些大写字母。我应该使用哪个str函数来提取仅以大写字母开头的内容?

尝试使用stringr

vec <- c("This", "is", "A", "test", "Sentence", "a")
library(stringr)
vec[str_detect(vec, "^[[:upper:]]")]
#> [1] "This"     "A"        "Sentence"

或使用基数r

grep("^[[:upper:]]", vec, value = TRUE)
#> [1] "This"     "A"        "Sentence"

由reprex包(v0.3.0)在2021-01-24创建

相关内容

最新更新