Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5546 > unrolled thread
| Started by | Richard Hofler <rhofler@bus.ucf.edu> |
|---|---|
| First post | 2011-10-09 07:57 +0000 |
| Last post | 2011-10-09 07:57 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: Sort on vector component Richard Hofler <rhofler@bus.ucf.edu> - 2011-10-09 07:57 +0000
| From | Richard Hofler <rhofler@bus.ucf.edu> |
|---|---|
| Date | 2011-10-09 07:57 +0000 |
| Subject | RE: Sort on vector component |
| Message-ID | <j6rk4d$1od$1@smc.vnet.net> |
Hello,
The answer that I believe you are looking for is given in the 3rd Basic Example in the Sort documentation:
u={{2,12,7,21},{2,48,47,97},{4,42,41,87},{6,8,1,15},{6,12,9,27}};
Sort[u] (* sort on 1st element in each sublist *)
Sort[u,#1[[2]]<#2[[2]]&] (* sort on 2nd element in each sublist *)
Sort[u,#1[[3]]<#2[[3]]&] (* etc. *)
Sort[u,#1[[4]]<#2[[4]]&]
{{2,12,7,21},{2,48,47,97},{4,42,41,87},{6,8,1,15},{6,12,9,27}}
{{6,8,1,15},{6,12,9,27},{2,12,7,21},{4,42,41,87},{2,48,47,97}}
{{6,8,1,15},{2,12,7,21},{6,12,9,27},{4,42,41,87},{2,48,47,97}}
{{6,8,1,15},{2,12,7,21},{6,12,9,27},{4,42,41,87},{2,48,47,97}}
Richard Hofler
________________________________________
From: Dr. Wolfgang Hintze [weh@snafu.de]
Sent: Saturday, October 08, 2011 5:36 AM
Subject: Sort on vector component
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
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web