Suppose I have the following two vectors. ll
defines the number and borderlines among sets of the elements in long
.
For example, here based on ll
, the first two elements in long
are a separate set, then the one element after those is a separate set, and so on.
I was wondering how I could automatically (perhaps as a sapply
) subset each set from long
based on ll
?
ll <- c(2, 1, 2, 3)
long <- c(F, F, F, F, T, T, F, T)