Let me be straightforward in telling that it may be a bit complicated for me to explain.
Let's assume that I have a vector with run-lengths of (forward) sliding window sizes.
xx <- c(3L, 2L, 1L, 4L, 4L, 3L, 3L, 1L, 2L, 1L, 2L, 3L, 4L, 3L, 2L, 1L)
xx
[1] 3 2 1 4 4 3 3 1 2 1 2 3 4 3 2 1
- First element is 3, which means window size (forward) for it, is of length 3. And so on.
- I want to assign first three (because 1st element is 3) elements a same group no. say 1
- Now I want to leave 2nd and 3rd elements - because they subsumed in first window and therefore these elements be allocated same group no. i.e. 1
- Pick 4th element then, it s window size is 4. Then allocate next four elements (including this one) another group no. say 2.
- Now pick 8th element (3+4 have been completed). and allocate unique group no say 3 to element count of its size which is 1 only.
- Next pick 9th element and so on.
- It is assured that last group will automatically be exhausted or it'll be 1.
My desired output is as below:
c(1, 1, 1, 2, 2, 2, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6)