MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: SortBy

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118207] Re: SortBy
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 16 Apr 2011 07:35:52 -0400 (EDT)

On 4/15/11 at 3:56 AM, graser at gmail.com (graser) wrote:

>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, ??]

In[2]:= SortBy[ks, #[[2]] &]

Out[2]= {{500, 23, 5}, {40, 32, 1}, {300, 48, 2}, {120, 55, 7}}



  • Prev by Date: ListLinePlot and Filling, or not ....
  • Next by Date: Re: SortBy
  • Previous by thread: Re: SortBy
  • Next by thread: Re: SortBy