Re: SortBy for multiple key sorts

• To: mathgroup at smc.vnet.net
• Subject: [mg124095] Re: SortBy for multiple key sorts
• From: Christopher Young <cy56 at comcast.net>
• Date: Sun, 8 Jan 2012 04:29:43 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <201201060916.EAA26845@smc.vnet.net> <CAEtRDScdXGAxq8bkV7zTBtBSi5CnK__M4CQr-V4fcZkvC7Kw-A@mail.gmail.com>

```On Jan 6, 2012, at 12:21 PM, Bob Hanlon wrote:

> pts = {{0, 2}, {1, 2}, {2, 2}, {4, 1}, {3, 1}, {6, 1}, {5, 1}, {7, 0}, {-1,
>    0}};
>
> sortByYthenX = SortBy[pts, {Min[#[[2]]] &, Min[#[[1]]] &}]
>
> {{-1, 0}, {7, 0}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {0, 2}, {1, 2}, {2, 2}}
>
> The Min isn't doing anything useful
>
> sortByYthenX ==
> SortBy[pts, {#[[2]], #[[1]]} &] ==
> SortBy[pts, {Last, First}] ==
> Reverse /@ Sort[Reverse /@ pts]
>
> True

Except that SortBy by default won't order irrationals except by the depth of their trees, or something like that. The normal expectation is that an irrational would be evaluated to machine precision, I would think.

In[83]:= SortBy[P, {#[[2]], #[[1]]} &]

Out[83]= {{-1, 0}, {0, 0}, {1, 0}, {-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}

To get the correcting sorting, rows across, going upwards from the bottom row, I have to take numerical evaluations:

In[84]:= SortBy[P, N@{#[[2]], #[[1]]} &]

Out[84]= {{-(1/2), -(Sqrt[3]/2)}, {1/2, -(Sqrt[3]/2)}, {-1,0}, {0,0}, {1, 0}, {-(1/2), Sqrt[3]/2}, {1/2, Sqrt[3]/2}}

```

• Prev by Date: Re: Sorting point-arrays by rows and columns, cont.
• Next by Date: Re: Prevent synchronizing a certain symbol between main and parallel
• Previous by thread: Re: SortBy for multiple key sorts
• Next by thread: Re: Re: SortBy for multiple key sorts