Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
让我们有一个字符向量,里面有一个逗号:
vector <- c("abcdefghi,jklmnopr")
如何获取带有逗号周围字符的向量?
# expecter outcome # "i,j"
对于内部带有多个逗号的向量,如何做到这一点?
vector <- c("ab,cdefghi,jklm,nopr") # expecter outcome # "b,c", "i,j", "m,n"
使用stringr包:
stringr
stringr::str_extract_all(vector, ".,.") # [[1]] # [1] "b,c" "i,j" "m,n"