I have two lists, one containing values, the other indices. Now I want to accumulate the values that have the same corresponding index. So for example:
values = {2, 6, 3, 8, 3, 1, 3, 7, 1, 3, 5}
indices = {1, 3, 1, 2, 3, 1, 1, 2, 3, 2, 1}
should give
result = {2 + 3 + 1 + 3 + 5, 8 + 7 + 3, 6 + 3 + 1}
I need to do this for very large lists, so it should be efficient.
Any ideas?
GatherBy[Transpose[{values, indices}], Last][[All, All, 1]]
$\endgroup$