Re: Sorting Rows of a Matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg65104] Re: Sorting Rows of a Matrix
- From: "J Siehler" <jsiehler at gmail.com>
- Date: Wed, 15 Mar 2006 06:28:15 -0500 (EST)
- References: <dv69a6$o6l$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Sort allows passing a comparison function as the second argument. Here's a 12x4 random matrix sorted by the second column. m = Table[Random[Integer, 30], {12}, {4}] m // MatrixForm Sort[m, #1[[2]] = #2[[2]] &] // MatrixForm If you do this frequently you might define sortMatrix[m_,key_]:=Sort[m, #1[[key]] = #2[[key]] &]