       SortBy for multiple key sorts

• To: mathgroup at smc.vnet.net
• Subject: [mg124026] SortBy for multiple key sorts
• From: Chris Young <cy56 at comcast.net>
• Date: Fri, 6 Jan 2012 04:16:01 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Finally figured out a reasonably simple way to sort by two keys, in
this case by the y-coordinates, and then within that sorting, by
x-coordinates. This is just a standard way to sort points: from bottom
to top in rows, and within each row from left to right. Why on earth
can't Sort take a list of ordering functions so that the same thing can
be done there?

In:= pts =
{
{0, 2}, {1, 2}, {2, 2},
{4, 1}, {3, 1}, {6, 1}, {5, 1},
{7, 0}, {-1, 0}
}

In:= sortByYthenX = SortBy[pts, {Min[#[]] &, Min[#[]] &}]

Out= {{-1, 0}, {7, 0}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {0,
2}, {1, 2}, {2, 2}}

• Prev by Date: Re: How to plot divergence of gradient as contour plot
• Next by Date: Re: How to plot divergence of gradient as contour plot
• Previous by thread: Re: Default sort of vector is by "complexity" of expression!!?????
• Next by thread: Re: SortBy for multiple key sorts