点号作为分隔符推荐转义处理 "\."
string="head.body.tail"
> stringr::str_split(string = string,pattern = "\\.",simplify = T)[,1]
[1] "head"
> stringr::str_split(string = string,pattern = "\\.",simplify = T)[,2]
[1] "body"
> stringr::str_split(string = string,pattern = "\\.",simplify = T)[,3]
[1] "tail"
也可以使用字符类"[.]"
> stringr::str_split(string = string,pattern = "[.]",simplify = T)
[,1] [,2] [,3]
[1,] "head" "body" "tail"
网友评论