Average of multiple vectors with different length
Your code is O(NM) because it iterates through every value, for every id. 

You need to iterate through the values once, adding the values to some structure which tracks the sum of every value for every id, and the number of values seen.

This lets you calculate average = (sum_values)/n_values in O(N+M), where N is number of values, M is number of ids.