Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Sort on vector component

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122015] Re: Sort on vector component
  • From: "Chris Degnen" <degnen at cwgsy.net>
  • Date: Sun, 9 Oct 2011 03:51:51 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

> To sort by the last position use SortBy[u, Last]
> and for other positions, say the third, use Ordering:
> u[[Ordering[u[[All, 3]]]]]

or, alternatively, SortBy[u, #[[3]] &]
 
> 
> Dr. Wolfgang Hintze wrote:
>>
>> Given a list
>> 
>> u = {{2, 12, 7, 21}, {2, 48, 47, 97}, {4, 42, 41, 87},
>> {6, 8, 1, 15}, {6, 12, 9, 27}}
>> 
>> How can I sort it with respect to a given index position i=(1, ..., 4)?
>> 
>> For i=1 it is simply Sort, for the last one I could use
>> 
>> In[75]:=
>> Reverse /@ Sort[Reverse /@ u]
>> Out[75]=
>> {{6, 8, 1, 15}, {2, 12, 7, 21}, {6, 12, 9, 27},
>> {4, 42, 41, 87}, {2, 48, 47, 97}}
>> 
>> I don't want to go in the details of defining lexicographical order but 
>> just obtain a sorting as described above.
>> 
>> Any ideas?
>> 
>> Thanks in advance.
>> 
>> Wolfgang
>> 
>>




  • Prev by Date: Re: "Esoteric of the week"
  • Next by Date: Laplace Trasform system of differential equation
  • Previous by thread: Re: Sort on vector component
  • Next by thread: Compilation of c mathlink