Re: sorting a Matrix
- To: mathgroup@smc.vnet.net
- Subject: [mg12281] Re: sorting a Matrix
- From: A Hayes <hay@haystack.demon.co.uk>
- Date: Thu, 7 May 1998 18:51:19 -0400
- References: <6ilpsl$jpo$12@dragonfly.wolfram.com>
Peter Klamser wrote:
> with Sort[{a,f,e,s}] I can sort a Vector (a List). How can I sort a
> Matrix??
>
> In the Help I can find the Information: Sort[{33,76,2,6,17},#1>#2&]
>
> For a Matrix I think it should work like this:
> Sort[{33,76,2,6,17},#1[[#5,#3]]>#2[[#4,#3]]&]
>
> where #3 is the column to be sorted for, and #5 and #4 are the different
> Vectors in the Matrix.
Peter:
m={{6,0,4},{5,8,5},{2,9,7}}
Sort by column 2:
Sort[m, #1[[2]]>= #2[[2]]&]
{{2,9,7},{5,8,5},{6,0,4}}
--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642