Suppose I have a vector v1 with 20 elements and another vector indicating groups within that other vector
v2=c(3, 10, 7)
This means the first group is the 3 first elements of v1, the second group the next 10 elements and finally the last group the last 7 elements.
I using a loop from 1 to 3 (the number of groups)
for (j in 1:3)
and need to choose the first 3 elements when j=1, the next 10 elements when j=2 and the last 7 when j=3
How could I do this inside the loop?