将1个字符串分成更多

时间:2011-03-18 10:13:45

标签: string r character

亲爱的, A有这样的字符串:

a <- "Good,Good*********,Good***********,Perfect,Perfect**********,Perfect***********"

现在我想把它分成这个:

a <- c("Good","Good*********","Good***********","Perfect","Perfect**********","Perfect***********")

非常欢迎任何建议!谢谢你,

Lisanne

2 个答案:

答案 0 :(得分:7)

strsplit这样做:

a<-"Good,Good***,Good****,Perfect,Perfect***,Perfect*****"
a <- strsplit(a, ",")[[1]]

答案 1 :(得分:0)

此类问题是scan

的完美候选
scan(text = a, what = "", sep = ",")
# Read 6 items
# [1] "Good"               "Good*********"      "Good***********"    "Perfect"   
# [5] "Perfect**********"  "Perfect***********"