Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: A little help with sort

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112512] Re: A little help with sort
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Sat, 18 Sep 2010 07:24:42 -0400 (EDT)
  • References: <i6vgmk$3ln$1@smc.vnet.net>

Am 17.09.2010 12:42, schrieb Blackwell, Keith:
> 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.

I think you want to look at SortBy, this is from its documentation:

SortBy[list,{f1,f2,...] breaks ties by successively using the values
obtained from the fi.

so I think what you described would be done with:

SortBy[matrix, {#[[1]] &, #[[2]] &,-#[[4]]&}]

hth,

albert



  • Prev by Date: Re: Need speed partitioning WeatherData
  • Next by Date: Re: front end equation formatting
  • Previous by thread: Re: A little help with sort
  • Next by thread: Re: A little help with sort