RE: sort
- To: mathgroup at smc.vnet.net
- Subject: [mg30002] RE: [mg29991] sort
- From: "Harvey P. Dale" <hpd1 at nyu.edu>
- Date: Sat, 21 Jul 2001 00:49:08 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Russ: 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 wish. Best. Harvey Professor Harvey P. Dale Director 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 asu.edu [mailto:nails at asu.edu] To: mathgroup at smc.vnet.net Sent: Friday, July 20, 2001 3:29 AM To: mathgroup at smc.vnet.net 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 asu.edu Thank you, --Russ-- _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. For further information visit http://www.messagelabs.com/stats.asp