我们有一个字符向量,里面带有一个逗号:
vector <- c("abcdefghi,jklmnopr")
如何获取带有逗号字符的向量?
# expecter outcome
# "i,j"
对于内部带有多个逗号的向量该怎么办?
vector <- c("ab,cdefghi,jklm,nopr")
# expecter outcome
# "b,c", "i,j", "m,n"
答案 0 :(得分:2)
使用stringr
软件包:
stringr::str_extract_all(vector, ".,.")
# [[1]]
# [1] "b,c" "i,j" "m,n"