开发者

separate 1 string into more

开发者 https://www.devze.com 2023-02-17 20:06 出处:网络
Dear All, A have a string like this: a <- \"Good,Good*********,Good***********,Perfect,Perfect**********,Perf开发者_如何学运维ect***********\"

Dear All, A have a string like this:

a <- "Good,Good*********,Good***********,Perfect,Perfect**********,Perf开发者_如何学运维ect***********"

now I want to separate this into this:

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

any suggestions are very welcome! Thanks you,

Lisanne


strsplit does this:

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


This type of problem is a perfect candidate for scan:

scan(text = a, what = "", sep = ",")
# Read 6 items
# [1] "Good"               "Good*********"      "Good***********"    "Perfect"   
# [5] "Perfect**********"  "Perfect***********"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号