MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Sorting on mulitple criteria

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115536] Sorting on mulitple criteria
  • From: Frank Letkiewicz <Frank.Letkiewicz at cadmusgroup.com>
  • Date: Thu, 13 Jan 2011 03:31:12 -0500 (EST)

What is the easiest way to sort a large data file using multiple criteria?

For example, if I had the following data set:

[cid:image002.png at 01CBB22A.226D2560]

[contact the author to get this - Moderator] 

How would I sort it so that it is largest to smallest based on the first value in each element, and within that it is largest to smallest based on the third value in each element so that the output is:

[cid:image004.png at 01CBB22A.226D2560]

[contact the author to get this - Moderator] 

I know I can use the following to get the sort right on the first value, but how do I incorporate the second sort criterion?

Sort[data,#1[[1]]>#2[[1]]&]

Thanks in advance,

Frank

data={{1,1,1},{1,1,2},{1,1,3},{1,2,1},{1,2,2},{1,2,3},{1,3,1},{1,3,2},{1,3,3},{2,1,1},{2,1,2},{2,1,3},{2,2,1},{2,2,2},{2,2,3},{2,3,1},{2,3,2},{2,3,3},{3,1,1},{3,1,2},{3,1,3},{3,2,1},{3,2,2},{3,2,3},{3,3,1},{3,3,2},{3,3,3}}



  • Prev by Date: Re: Curl and Div problems
  • Next by Date: Re: Curl and Div problems
  • Previous by thread: Re: Styles for inline boxes
  • Next by thread: Re: Sorting on mulitple criteria