I\'m trying to figure out an efficient way to go about splitting a string like
\"111110000011110000111000\"
into a vector
[1] \
How about this:
s <- "111110000011110000111000" spl <- strsplit(s,"10|01")[[1]] l <- length(spl) sapply(1:l, function(i) paste0(spl[i],i%%2,ifelse(i==1 | i==l, "",i%%2))) # [1] "11111" "00000" "1111" "0000" "111" "000"