逗号分隔字符串拆分

时间:2017-03-17 21:08:21

标签: r

我尝试转换此向量字符串

(l.append(x) or l) if x not in l else l

进入这个

a<-c("1,2,3","344")

我使用以下代码:

a<-c("1","2","3","344")

但是我要回到原始载体:

a<-c("1,2,3","344")

b<-strsplit(a, ",")

c<-sapply( b, paste0, collapse=",")

任何帮助都将不胜感激。

谢谢,

阿尔比特

2 个答案:

答案 0 :(得分:4)

尝试:

a <- c("1,2,3","344")
scan(text = a, sep = ",", what = "")
# [1] "1"   "2"   "3"   "344"

答案 1 :(得分:1)

此解决方案与我的评论相同:

a <- c("1,2,3", "344")
b <- unlist(strsplit(a, ","))
b
[1] "1"   "2"   "3"   "344"