       Re: Sorting Rows of a Matrix

• To: mathgroup at smc.vnet.net
• Subject: [mg65119] Re: Sorting Rows of a Matrix
• From: dh <dh at metrohm.ch>
• Date: Wed, 15 Mar 2006 06:28:35 -0500 (EST)
• References: <dv69a6\$o6l\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Greg,
you can solve thhis problem by using the second argument of Sort (see
the manual). E.g. r will choose the sorting row:

m={{1,3},{2,2},{3,1}};
r=1;
Sort[m, #1[[r]] < #2[[r]] &]

with r=2 we get: {{1, 3}, {2, 2}, {3, 1}}
with r=2 we get: {{3, 1}, {2, 2}, {1, 3}}

Daniel

Gregory Lypny wrote:
> Hello everyone,
>
> How can I sort the rows of a matrix by using one or more of the
> columns as sort keys just like in a spreadsheet?  For example, if
> matrix M is 12 x 2 with numbers in the first column and unordered
> month numbers in the second, how would I order the rows by month?
>
> 	Regards,
>
> 		Greg
>

```

• Prev by Date: Re: Writing regular text?
• Next by Date: Re: Sorting Rows of a Matrix
• Previous by thread: RE: Sorting Rows of a Matrix
• Next by thread: Re: Sorting Rows of a Matrix