MathGroup Archive 2011

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

Search the Archive

Re: SortBy

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118198] Re: SortBy
  • From: Peter Pein <petsie at dordos.net>
  • Date: Sat, 16 Apr 2011 07:34:11 -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?
>
> SortBy[KS, ??]
>
> Thanks!
>
>

according to http://reference.wolfram.com/mathematica/ref/SortBy.html 
the following should give True as result:

In[70]:= Sort[KS, #2[[2]] > #1[[2]] &] === KS[[Ordering[KS[[All, 2]]]]] 
=== SortBy[KS, #[[2]] &] === SortBy[KS, Rest]
Out[70]= True

hth,
Peter


  • Prev by Date: Re: concatenate matrices?
  • Next by Date: Removing strange characters from mathgroup postings
  • Previous by thread: Re: SortBy
  • Next by thread: Re: SortBy