Split string based on alternating character in R

后端 未结 9 432
醉话见心
醉话见心 2021-01-30 10:02

I\'m trying to figure out an efficient way to go about splitting a string like

\"111110000011110000111000\"

into a vector

[1] \         


        
9条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 10:47

    Variation on a theme:

    x <- "111110000011110000111000"
    regmatches(x,gregexpr("1+|0+",x))[[1]]
    #[1] "11111" "00000" "1111"  "0000"  "111"   "000"
    

提交回复
热议问题