如下所示的拆分使我发疯...需要一些帮助才能发现问题出在哪里
> p5<-Data$poorcoverageusers[5]
> p5
[1] "405874050693761|405874004853834|405874056470063|405874055308702"
> strsplit(p5,"|")
[[1]]
[1] "4" "0" "5" "8" "7" "4" "0" "5" "0" "6" "9" "3" "7" "6" "1" "|" "4" "0" "5" "8" "7" "4" "0" "0" "4" "8" "5" "3" "8" "3" "4" "|" "4" "0" "5"
[36] "8" "7" "4" "0" "5" "6" "4" "7" "0" "0" "6" "3" "|" "4" "0" "5" "8" "7" "4" "0" "5" "5" "3" "0" "8" "7" "0" "2"
> typeof(Data$poorcoverageusers[5])
[1] "character"
我希望将其用“ |”分隔...因此输出应为405874050693761 405874004853834 405874056470063 405874055308702
我在犯什么错误。
寻求帮助
r
答案 0 :(得分:0)
library(stringr)
s <- "405874050693761|405874004853834|405874056470063|405874055308702"
str_split(s, fixed("|")) # returns a list of character vectors
# [[1]]
# [1] "405874050693761" "405874004853834" "405874056470063" "405874055308702"
str_split(s, fixed("|"), simplify = T) # returns a character matrix
# [,1] [,2] [,3] [,4]
# [1,] "405874050693761" "405874004853834" "405874056470063" "405874055308702"