Re: SortBy
- To: mathgroup at smc.vnet.net
 - Subject: [mg118215] Re: SortBy
 - From: Bob Hanlon <hanlonr at cox.net>
 - Date: Sat, 16 Apr 2011 07:37:38 -0400 (EDT)
 
KS = {{300, 48, 2}, {500, 23, 5}, {120, 55, 7}, {40, 32, 1}};
As shown on the Help page
SortBy[KS, Last]
{{40, 32, 1}, {300, 48, 2}, {500, 23, 5}, {120, 55, 7}}
or
SortBy[KS, #[[-1]] &]
{{40, 32, 1}, {300, 48, 2}, {500, 23, 5}, {120, 55, 7}}
Bob Hanlon
---- graser <graser at gmail.com> wrote: 
=============
Dear Mathematica group,
I have a simple question for you.
Let's say there is a list like
KS = {{300, 48, 2}, {500, 23, 5}, {120, 55, 7}, {40, 32, 1}};
I want to sort it by second element.
I can use
Sort[KS, #2[[2]] > #1[[2]] &]
It gives out like
{{500, 23, 5}, {40, 32, 1}, {300, 48, 2}, {120, 55, 7}}
But if I want to use SortBy, how to do that?
SortBy[KS, ??]
Thanks!