If I have a vector c(2, 1, 0) where the sum of the vector is always equal to the length of the vector, is it possible for me to select data from another vector in a way where I would get 2 of the first element, 1 of the second element, and none of the third element? More generally, for vectors a and index, where sum(index) == length(index) I would get index[i] number of a[i].
I hope this was clear enough, but its fairly muddled in my head. I can implement this with loops, but I’d like a vector based solution.
Thanks!
I might add that the property that
sum(index) == length(index)is not enforced. That would be something for which your process for constructing “index” remains responsible.