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.
有没有一种简单的方法可以用 R 中字符向量的每个元素中的点替换破折号?
input c("T-A-B", "C-L1") output c("T.A.B", "C.L1")
正在寻找stringi包裹中的帮助,但找不到答案。有stri_substitute功能,但不知道怎么用。
stringi
stri_substitute
像这样的基础R(gsub 矢量化感谢@docendo):
R
> gsub("-",".",c("T-A-B", "C-L1")) [1] "T.A.B" "C.L1"
或与stringr:
stringr
> library(stringr) > str_replace_all( c("T-A-B", "C-L1"),"-",".") [1] "T.A.B" "C.L1"