separate 1 string into more

核能气质少年 提交于 2019-12-08 08:14:43

问题


Dear All, A have a string like this:

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

now I want to separate this into this:

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

any suggestions are very welcome! Thanks you,

Lisanne


回答1:


strsplit does this:

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



回答2:


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***********"


来源:https://stackoverflow.com/questions/5350523/separate-1-string-into-more

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!