MathGroup Archive 2011

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

Search the Archive

Re: Does Union[] reliably sort?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123731] Re: Does Union[] reliably sort?
  • From: markholtuk <markholtuk at googlemail.com>
  • Date: Sat, 17 Dec 2011 02:39:33 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jca06e$a35$1@smc.vnet.net>

You can get an unsorted Union using a combination of Join and
DeleteDuplicates as follows:

In[1]:= mins = {{{2001, 1, 31}, 0.993268}, {{2002, 3, 31},
    1.01395}, {{2003, 6, 30}, 1.08647}, {{2005, 11, 30},
    1.14752}, {{2006, 9, 30}, 1.18938}, {{2007, 2, 28},
    1.19658}, {{2008, 1, 31}, 1.20432}, {{2011, 1, 31}, 1.37501}};

maxs = {{{2000, 10, 31}, 1.01816}, {{2001, 12, 31},
    1.02714}, {{2004, 2, 29}, 1.12702}, {{2005, 3, 31},
    1.16986}, {{2010, 10, 31}, 1.39026}};

uni = Union[maxs, mins]

Out[3]= {{{2000, 10, 31}, 1.01816}, {{2001, 1, 31},
  0.993268}, {{2001, 12, 31}, 1.02714}, {{2002, 3, 31},
  1.01395}, {{2003, 6, 30}, 1.08647}, {{2004, 2, 29},
  1.12702}, {{2005, 3, 31}, 1.16986}, {{2005, 11, 30},
  1.14752}, {{2006, 9, 30}, 1.18938}, {{2007, 2, 28},
  1.19658}, {{2008, 1, 31}, 1.20432}, {{2010, 10, 31},
  1.39026}, {{2011, 1, 31}, 1.37501}}

In[4]:= del = DeleteDuplicates[Join[maxs, mins]]

Out[4]= {{{2000, 10, 31}, 1.01816}, {{2001, 12, 31},
  1.02714}, {{2004, 2, 29}, 1.12702}, {{2005, 3, 31},
  1.16986}, {{2010, 10, 31}, 1.39026}, {{2001, 1, 31},
  0.993268}, {{2002, 3, 31}, 1.01395}, {{2003, 6, 30},
  1.08647}, {{2005, 11, 30}, 1.14752}, {{2006, 9, 30},
  1.18938}, {{2007, 2, 28}, 1.19658}, {{2008, 1, 31},
  1.20432}, {{2011, 1, 31}, 1.37501}}

In[5]:=uni === del

Out[5]= False

In[6]:= sortdel = Sort[del]

Out[6]= {{{2000, 10, 31}, 1.01816}, {{2001, 1, 31},
  0.993268}, {{2001, 12, 31}, 1.02714}, {{2002, 3, 31},
  1.01395}, {{2003, 6, 30}, 1.08647}, {{2004, 2, 29},
  1.12702}, {{2005, 3, 31}, 1.16986}, {{2005, 11, 30},
  1.14752}, {{2006, 9, 30}, 1.18938}, {{2007, 2, 28},
  1.19658}, {{2008, 1, 31}, 1.20432}, {{2010, 10, 31},
  1.39026}, {{2011, 1, 31}, 1.37501}}

In[7]:=uni === sortdel

Out[7]= True

Cheers,

Mark



  • Prev by Date: Re: precision of y-axis values in plot
  • Next by Date: Re: Printing Mathematica Notebooks and WYSIWYG
  • Previous by thread: Re: Does Union[] reliably sort?
  • Next by thread: Re: Does Union[] reliably sort?