MathGroup Archive 2007

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

Search the Archive

Re: Sorting by date

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72665] Re: Sorting by date
  • From: "Drago Ganic" <dganic at vodatel.net>
  • Date: Sun, 14 Jan 2007 04:46:47 -0500 (EST)
  • References: <eoa6ji$mi6$1@smc.vnet.net>

Hi,
you should use Sort but change the default ordering function from
OrderedQ[{#1, #2}] &
to
OrderedQ[{#1[[3]], #2[[3]]}] &

because it's only the third column you would like to use for sorting.


Here is yoz example:

tbl = {
{3, 137.5, 13978, {2005, 2, 8}},
{3, 138.5, 12519, {2005, 1, 4}},
{3, 171.9, 15835, {2005, 4, 12}},
{3, 142.8, 17137, {2005, 11, 19}},
{3, 161.1, 18881, {2006, 1, 18}},
{3, 108.7, 20055, {2006, 2, 28}},
{3, 157, 21498,    {2006, 9, 14}},
{3, 118.1, 10891, {2004, 11, 12}}
}

Sort[data, OrderedQ[{#1[[3]], #2[[3]]}] & ]

{
{3, 118.1, 10891, {2004, 11, 12}},
{3, 138.5, 12519, {2005, 1, 4}},
{3, 137.5, 13978, {2005, 2, 8}},
{3, 171.9, 15835, {2005, 4, 12}},
{3, 142.8, 17137, {2005, 11, 19}},
{3, 161.1, 18881, {2006, 1, 18}},
{3, 108.7, 20055, {2006, 2, 28}},
{3, 157, 21498, {2006, 9, 14}}
}


You can use $PrePrint = TableForm[#1, TableDepth -> 2] & for printing this 
table.

Greetings from Croatia,
Drago Ganic

"Clifford Martin" <camartin at snet.net> wrote in message 
news:eoa6ji$mi6$1 at smc.vnet.net...
> Hi All,
>
> I have a list of lists that looks like so:
>
>
> {{3, 137.5, 13978, {2005, 2, 8}}, {3, 138.5, 12519, {2005, 1, 4}}, {3, 
> 171.9, 15835, {2005, 4, 12}}, {3, 142.8, 17137, {2005, 11, 19}},
>  {3, 161.1, 18881, {2006, 1, 18}}, {3, 108.7, 20055, {2006, 2, 28}}, {3, 
> 157, 21498, {2006, 9, 14}}, {3, 118.1, 10891, {2004, 11, 12}}}
>
> The last element per vector is a date. I'd like to sort the list so that 
> the vectors are arranged in ascending order of date, i.e. the vector 
> containing {2004,11,12}  should be first and and the vector containing 
> {2006,9,14}  should be last. Any help would be appreciated.
>
> Thanks
>
> Cliff
> 



  • Prev by Date: Re: Sorting by date
  • Next by Date: a problem with integrate
  • Previous by thread: Re: Sorting by date
  • Next by thread: Re: Sorting by date