MathGroup Archive 2011

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

Search the Archive

Re: SortBy

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118211] Re: SortBy
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 16 Apr 2011 07:36:40 -0400 (EDT)
  • References: <io8to0$qbf$1@smc.vnet.net>

Am 15.04.2011 09:56, schrieb graser:
> 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?
>

While there are functions First and Last, there is no Second and Third, 
but maybe that's an inexpensive possibility to increase the number of 
functions in the next version even more :-).

But you can use a pure function:

SortBy[KS, #[[2]] &]

hth,

albert


  • Prev by Date: Re: trouble printing to PDF
  • Next by Date: Re: concatenate matrices?
  • Previous by thread: Re: SortBy
  • Next by thread: Re: SortBy