"Sloppy Union"? (Union of a list with *nearly* equal elements)
- To: mathgroup at smc.vnet.net
- Subject: [mg41892] "Sloppy Union"? (Union of a list with *nearly* equal elements)
- From: AES/newspost <siegman at stanford.edu>
- Date: Sun, 8 Jun 2003 06:45:53 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I'm trying to make a "Sloppy Union" that will eliminate elements of a list that are *almost* but not precisely duplicates of each other; and Union[ ] has the "SameTest->test" option which looks like what I need. I don't understand, however, why the following approach seems to work Remove["Global`*"] sloppyData = Table[Random[Integer, {1000,1005}] + Random[Real, {-0.01,0.01}], {20}] Union[sloppyData, SameTest -> (Abs[#1-#2]<10.^-1&)] but the following doesn't Remove["Global`*"] sloppyData = Table[Random[Integer, {1000,1005}] + Random[Real, {-0.01,0.01}], {20}] sharperData = SetPrecision[sloppyData, 4] Union[sharperData, SameTest -> (Abs[#1-#2]<10.^-1&)] --even though shaperData seems to have reduced precision. P.S. to Wolfram: Although "SameTest->test" is listed as an option in the online Help, neither "SameTest" or "test" are explained in the online Help system, and the only example of SameTest given in The Mathematica Book has the syntax "SameText -> comp" rather than "SameTest->test". Are "test" and "comp" the same? -- "Power tends to corrupt. Absolute power corrupts absolutely." Lord Acton (1834-1902) "Dependence on advertising tends to corrupt. Total dependence on advertising corrupts totally." (today's equivalent)