Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

RE: sort

  • To: mathgroup at
  • Subject: [mg30002] RE: [mg29991] sort
  • From: "Harvey P. Dale" <hpd1 at>
  • Date: Sat, 21 Jul 2001 00:49:08 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

	Suppose mat={{1,2},{2,4},{1,3},{2,1},{2,7},{1,5}}.  A simple Sort
statement (Sort[mat]) produces {{1,2},{1,3},{1,5},{2,1},{2,4},{2,7}}.  Isn't
that what you want?
	There are more complicated ways to do this, of course, that give you
more control over the ordering functions.  For example, you can first sort
by the second key and then sort the resulting output by the first key.
Using the same less-than-or-equal-to operators, this would look like this:
Sort[Sort[mat,#1[[2]]<=#2[[2]]&],#1[[1]]<=#2[[1]]&].  It produces the same
output as above, but shows how you could change the ordering rule(s) if you
Professor Harvey P. Dale
National Center on Philanthropy and the Law
New York University School of Law
Room 206A
110 West 3rd Street
New York, N.Y. 10012-1074
tel: 212-998-6161
fax: 212-995-3149

 -----Original Message-----
From: 	nails at [mailto:nails at] 
To: mathgroup at
Sent:	Friday, July 20, 2001 3:29 AM
To:	mathgroup at
Subject:	[mg29991] sort

Does anybody now how to sort a matrix first by one column and then by
another column (giving priority to the first column and sorting by
second column only when there are ties in the first column).

Please respond to nails at

Thank you,

This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit

  • Prev by Date: Re: Integrate[Sqrt[Tan[x]], {x, 0, 1}] -- approx ??
  • Next by Date: Delay in $Context changes taking effect?
  • Previous by thread: Re: sort
  • Next by thread: Re: Re: sort