MathGroup Archive 2011

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

Search the Archive

Re: SortBy

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118191] Re: SortBy
  • From: Eric Brown <eric.c.brown at mac.com>
  • Date: Sat, 16 Apr 2011 07:32:55 -0400 (EDT)

I think that it takes the head of some function:

KS={{300,48,2},{500,23,5},{120,55,7},{40,32,1}};

(* define a new function *)
secondElement[x_]:=x[[2]]
SortBy[KS,secondElement]
Out[17]= {{500,23,5},{40,32,1},{300,48,2},{120,55,7}}

Or even a pure function:
SortBy[KS, (#[[2]]&)]
Out[18]= {{500,23,5},{40,32,1},{300,48,2},{120,55,7}}

SortBy[KS, (Part[#,2]&)]
Out[19]= {{500,23,5},{40,32,1},{300,48,2},{120,55,7}}


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