Suppose I have the following list of data
{{1,2},{1,5},{6,1},{1,3},{2,1},{2,2},{2,3},{5,4},{5,2}}
This is similar to my actual data in that each x value has several y values, potentially different numbers of y values, I don't necessarily have all of the x values, and the x values could be disordered. I want to combine this data set to look like {{1,10},{2,6},{5,6},{6,1}}, where I keep only the unique x values and have the sum of all the y values for that x value as the new y value. The sorting doesn't necessarily have to happen, but would be convenient if it did.
Is there a better way to do this than in a For loop going through each pair looking for the same x value and adding it to the relevant y value? I worry that this would be extremely inefficient for my actual data set which has several thousand points over a hundred or so x values.
// SortBy[First]to the end of the code. – Karsten7 Jul 08 '15 at 13:59