使用grepl查找一定长度的字符串
Using grepl to find strings of a certain length
样本数据
a<-c("hi","four","seven", "six", "high")
如何 select 所有长度等于 4 的字符串?
这是我的尝试
a[grepl(length(a)==4,]
您似乎需要 nchar
函数。 grep
及其对应物在字符串中查找字符串,length
描述向量或列表中的条目数
> nchar(a)
[1] 2 4 5 3 4
> a[nchar(a)==4]
[1] "four" "high"
样本数据
a<-c("hi","four","seven", "six", "high")
如何 select 所有长度等于 4 的字符串?
这是我的尝试
a[grepl(length(a)==4,]
您似乎需要 nchar
函数。 grep
及其对应物在字符串中查找字符串,length
描述向量或列表中的条目数
> nchar(a)
[1] 2 4 5 3 4
> a[nchar(a)==4]
[1] "four" "high"