String transformation in R | Grouping words of a string

后端 未结 5 1284
孤街浪徒
孤街浪徒 2021-01-20 10:02

I want to group the words of string(given below)

text=\"Lorem,ipsum,dolor,sit,amet,consectetuer\"

like this

textNew=\"Lore         


        
5条回答
  •  误落风尘
    2021-01-20 10:17

    Ahh got something similar.

    text="Lorem,ipsum,dolor,sit,amet,consectetuer"
    text2 <- unlist(strsplit(text, ","))
    textNew=paste0(sapply(1:(length(text2)-1),function(i,y=text2){paste(y[i],y[i+1])}),collapse=",")
    

提交回复
热议问题