re:sort pairs
- To: mathgroup at yoda.physics.unc.edu
- Subject: re:sort pairs
- From: wmm at chem.wayne.edu (Martin McClain)
- Date: Mon, 15 Nov 93 10:55:13 EST
> How can I sort pairs of values -- basing the sort on the first value
> and then break ties on the second value in the pair.
>
> Let's say I have n pairs on numbers in the following matrix
>
> data = { {x1,y1}, .....{xi, yi}, .....{xn,yn} }
>
> Using the Sort function in Mma, I can easily sort on the xi values, but
> how can I do the secondary sort on the yi values??
I think this happens automatically. I just tried
Sort[ {{5,9},{2,7},{5,6},{7,1},{5,2}}]
with many permutations of the interior pairs, and the answer always comes
out as
{{2,7},{5,2},{5,6},{5,9},{7,1}}.
Isn't this exactly what you want?
Regards- Martin