Re: A little help with sort
- To: mathgroup at smc.vnet.net
- Subject: [mg112520] Re: A little help with sort
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Sat, 18 Sep 2010 07:26:13 -0400 (EDT)
data = RandomInteger[4, {25, 5}]; (sort1 = SortBy[Reverse[SortBy[data, #[[4]] &]], {#[[1]] &, #[[2]] &}]) // Grid When column 4 is all numeric, then (sort2 = SortBy[data, {#[[1]] &, #[[2]] &, -#[[4]] &}]) // Grid Bob Hanlon ---- "Blackwell wrote: ============= The problem I am having: Let's say I have a 200 x 200 matrix. I want to sort it in order of the values in column one. Then I want it to sort all the doubles by the values in column two. Then I want it to sort all the double doubles by reverse of the values of column 4 or whatever. Is there an easy way to do this. I know I can write something long and annoying to do it, but I'm getting to the point in my use of mathematica where I want to write more concise code. Sort[Matrix, #1[[1]]>#2[[1]]&] seems to totally negate any pre sorting... I tried to fold it backwards starting from column 4 and it seems that sort just ignores whatever I do then. Thanks in advance, Keith