问题
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