Imagine I have the following list
l = {{1, 2}, {1, 3}, {2, 4}, {2, 2}, {2, 3}}
I want to take the mean only regarding the second element. That is, I want to find the coordinates of the points corresponding to
{{1, 2.5}, {2, 3}}
What is the easiest way to achieve this? In other words, how can I easily compute the mean points (in red) from a list of coordinates
My approach: Mean /@ Split[Sort@l, Last[#2] >= Last[#1] &]
. Could this be improved?
Mean /@ GatherBy[alist, First]
? (wherealist
is the list in the OP.l
is hard to read. $\endgroup$