Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Sorting question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52791] Re: [mg52758] Sorting question
  • From: DrBob <drbob at bigfoot.com>
  • Date: Mon, 13 Dec 2004 04:22:55 -0500 (EST)
  • References: <200412111023.FAA06589@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Maybe your data looked like {{1, 1}, {2, 3}, {3, 2}, {4, 4}}, rather than having all those parentheses?

Anyway, here's a method that may work for you:

data={{1,1},{2,3},{3,2},{4,4}}
remover={a___,{d1_,t1_},{d2_,t2_},b___}/;t2<t1:>{a,b};
Sort@data/.remover

{{1,1},{2,3},{3,2},{4,4}}

{{1,1},{4,4}}

data=RandomArray[ExponentialDistribution[0.1],{17,2}];
Sort@data
%/.remover

{{0.0384055,17.9033},{0.204296,6.29239},{0.575515,11.7231},{0.831196,3.07496},\
{1.5744,4.58849},{1.91661,8.39652},{2.25087,54.8277},{2.69083,6.83991},{2.\
98937,10.3344},{4.80607,19.9063},{5.58785,0.687047},{8.57433,21.1495},{8.\
75018,19.6064},{10.1908,7.97579},{10.9566,25.7916},{11.3327,8.29348},{25.78,8.\
40211}}

{{0.575515,11.7231},{0.831196,3.07496},{
   1.5744,4.58849},{1.91661,8.39652},{2.25087,54.8277},{
     2.69083,6.83991},{2.98937,10.3344},{4.80607,19.9063},{5.58785,0.687047},{
     8.57433,21.1495},{8.75018,19.6064},{10.1908,7.97579},{
   10.9566,25.7916},{11.3327,8.29348},{25.78,8.40211}}

Bobby

On Sat, 11 Dec 2004 05:23:38 -0500 (EST), Nimrod <jdedguard-agent at yahoo.co.uk> wrote:

>  A simple sorting question that has me stumped as to how to do it both
> quickly and elegantly.
>
> I have a list of data pairs of the form (distance, time).  I want to
> sort on the distance element and then remove all pairs where the time
> element is out of order with the distance element.  For example
> ((1,1),(2,3),(3,2),(4,4)) --> ((1,1),(4,4)).  The actual lists are
> much longer.
>
> Thanks in advnace,
>
> Nimrod.
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: MMA 5.1 Integrals
  • Next by Date: Re: Using LevenbergMarquardt Method with a complicated function
  • Previous by thread: Re: Sorting question
  • Next by thread: Re: Sorting question