y <- data.frame(x = c("63,98,131","75,109,145","66,104,139"))
我想通过从逗号
分割来从x创建三列A,B,C A B C
63 98 131
75 109 145
66 104 139
我尝试使用str_split
str_split(y$x, " , ")
[[1]]
[1] "63,98,131"
[[2]]
[1] "75,109,145"
[[3]]
[1] "66,104,139"
但这不起作用。我该如何解决?
答案 0 :(得分:0)
> dt=as.data.frame(matrix(unlist(strsplit(y$x,",")),ncol=dim(y)[1],byrow = T))
> dt
V1 V2 V3
1 63 98 131
2 75 109 145
3 66 104 139