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

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

Search the Archive

Re: SameTest in Union

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61407] Re: SameTest in Union
  • From: delouis at bellsouth.net
  • Date: Tue, 18 Oct 2005 02:44:55 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> There may be other ways to do this, but I thought of Union first.

Hi. You have great solution using Union. As an alternative, Split could be another method.
This may allow you to apply your own function to extract what you consider the "best."
For example, if a group of numbers are all close, you may prefer to extract the integer number if available.

data = {0.99, 1, 1.01, 1.99, 2, 2.01,
2.99, 3., 3.01, 3.02, 3.03};

v = Split[data, Abs[#1 - #2] <= 0.1 & ]

{{0.99, 1, 1.01}, {1.99, 2, 2.01}, {2.99, 3., 3.01, 3.02, 3.03}}


Numbers are grouped. You can now apply your own function to extract the integer if available, middle number, Average, Mode, Median, etc...

--
Dana DeLouis
Win XP & Office 2003


"Jack Goldberg" <jackgoldberg at comcast.net> wrote in message news:did38g$qht$1 at smc.vnet.net...
> Hi Folks,
>
> I know there is a simple answer to this question but the help index
> idoes not help!
>
> I have a list, something like this:
>
> lst = {1.1101, 1.11095, 1.11076, 1.09, 2.3523, 2.352. 2.35211}
>
> I want to remove from the list those entries which are near each
> other but not identical, leaving only one representative for each of
> these numbers. One approach is to use Union with the option
> SameTest->???. Here the same test might be that the difference
> between entries is less than, say 10^(-2). But I can't seem to get
> SameTest to work. So, what I want is
>
> Union[ lst, SameTest- > ?]
>
> so that the union returns
>
> {1.1101, 2.35211}
>
> Here, I chose 2 representatives. Any other choice is OK; say,
>
> {1.11095, 2.352}
>
> is also satisfactory.
>
> There may be other ways to do this, but I thought of Union first.
> Perhaps, Cases or Select might be better. Any help is appreciated.
>
> Jack


  • Prev by Date: Re: Re: Element test
  • Next by Date: Re: Displaying Solution in Matrix Form
  • Previous by thread: Re: SameTest in Union
  • Next by thread: Problem with circles in complex plane