Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*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 1995

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

Search the Archive

Re: Sort[] accuracy problem

  • To: mathgroup at christensen.cybernetics.net
  • Subject: [mg1145] Re: Sort[] accuracy problem
  • From: roth at sunny.mpimf-heidelberg.mpg.de (Arnd Roth)
  • Date: Wed, 17 May 1995 04:59:24 -0400
  • Organization: Max-Planck-Institut fuer Medizinische Forschung

In article <3p657h$kb1 at news0.cybernetics.net>
"Wm. Martin McClain" <wmm at chem.wayne.edu> writes:

> Here is the kind of thing that is giving me trouble:
> 
> In[299]:= Sort[{{5.00, 1}, {4.00, 3}, {1.00, 2}, {4.01, 1}}]
> Out[299] =     {{1.00, 2}, {4.00, 3}, {4.01, 1}, {5.00, 1}}
> 
> But I would like it to treat 4.00 and 4.01 as the same for the 
> purposes of sorting, so that it returns the approximately 
> alphebetized list
> 
>                {{1.00, 2}, {4.01, 1}, {4.00, 3}, {5.00, 1}}
> 
> where the difference between 1 and 3 is treated as more 
> important than the difference between 4.00 and 4.01.I tried 
> 
>                Sort[list,(Round[#2*10]<Round[#1*10])&], 
> 
> but it seems to think that #n refers to the whole point {x,y}, 
> rather than just to x (or on the second round, just to y), so the 
> comparison becomes neither True nor False and no sorting is done.

The first part of {x, y} is x, so let's just compare the first
parts:

In[1]:= list = {{5.00, 1}, {4.00, 3}, {1.00, 2}, {4.01, 1}}
Out[1]= {{5., 1}, {4., 3}, {1., 2}, {4.01, 1}}

In[2]:= Sort[list, Round[First[#1]*10] < Round[First[#2]*10] &]
Out[8]= {{1., 2}, {4.01, 1}, {4., 3}, {5., 1}}

Arnd Roth
Abteilung Zellphysiologie
Max-Planck-Institut fuer Medizinische Forschung
Postfach 10 38 20, D-69028 Heidelberg, Germany
http://sunny.mpimf-heidelberg.mpg.de/people/roth/ArndRoth.html


  • Prev by Date: Finding Regression Coefficient
  • Next by Date: Re: How fast are Mathematica Versions ?
  • Previous by thread: Re: Finding Regression Coefficient
  • Next by thread: Sort[] accuracy problem