I\'ve got a vector of binary numbers. I know the consecutive length of each group of objects; how can I split based on that information (without for loop)?
x
Another option is
split(x,cumsum(sequence(.length)==1)) #$`1` #[1] "1" "0" #$`2` #[1] "1" "0" "0" "0" #$`3` #[1] "0" "0" "1"
to get the group names
group names
split(x, sub('.$', '', names(sequence(.length)))) #$group1 #[1] "1" "0" #$group2 #[1] "1" "0" "0" "0" #$group3 #[1] "0" "0" "1"