Re: Sorting on multiple columns within a matrix

• To: mathgroup at smc.vnet.net
• Subject: [mg57837] Re: Sorting on multiple columns within a matrix
• From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
• Date: Thu, 9 Jun 2005 06:12:01 -0400 (EDT)
• Organization: Uni Leipzig
• References: <d892lm\$sc6\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi,

Sort[M, If[#1[[2]] =!= #2[[2]], #1[[2]] < #2[[2]],
#1[[1]] < #2[[1]]] &]

??

Regards

Jens

"Lee Newman" <leenewm at umich.edu> schrieb im
Newsbeitrag news:d892lm\$sc6\$1 at smc.vnet.net...
> Hello,
>
> I can't come up with a solution to the following
>
> -  I have a matrix, let's M={
> {"Z",2,"a"},{"A",2,"k"}, {"Z",1,"z"},
> {"A",1,"a"},{"Z",3,"k"}, {"A",3,"z"} }
> -  I want to be able to sort the matrix
> row-wise, based on multiple
> columns, for example sort first on column 2
> (ascending) and then
> secondly on column1 (ascending)
>
> desired result:
> A 1 a
> Z 1 z
> A 2 k
> Z 2 a
> A 3 z
> Z 3 k
>
> I suspect the solution involves using a pure
> function of some form as
> the second argument in the Sort function, but I
> can't figure out what
> this function should be.
>
> Thanks,
> Lee
>

```

• Prev by Date: Re: Centering of graphics
• Next by Date: Re: Point Sampling in Digital Image Processing?
• Previous by thread: Re: Sorting on multiple columns within a matrix
• Next by thread: Re: Sorting on multiple columns within a matrix