[英]Using grepl to find strings of a certain length
樣本數據
a<-c("hi","four","seven", "six", "high")
如何選擇所有長度等於4的字符串?
這是我的嘗試
a[grepl(length(a)==4,]
看起來您想要nchar
函數。 grep
及其對應項在字符串中查找字符串, length
描述向量或列表中的條目數
> nchar(a)
[1] 2 4 5 3 4
> a[nchar(a)==4]
[1] "four" "high"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.