Reputation: 57
i want to convert "hello,world" into vector as "hello","world"
i tried splitting as below:
c<- "hello,world"
spl<-unlist(strsplit(c, ","))
but I am getting result as below:
"hello" "world"
I want my result as:
"hello","world"
Upvotes: 0
Views: 45
Reputation: 253
cc<- str_split(cc,",")[[1]]
#Then use shQuote() to make each element of vector quoted string and then use paste() to make them comma separated.
print(paste(shQuote(cc), collapse=", "))
Upvotes: 0
Reputation: 102349
Do you mean this?
> cat(gsub("(\\w+)", "\"\\1\"", s), "\n")
"a","b","c","d"
Data
s <- "a,b,c,d"
Upvotes: 1