MathGroup Archive 2011

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

Search the Archive

Re: List Manipulation- Advanced beginner question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121599] Re: List Manipulation- Advanced beginner question
  • From: Nguyen Van Falk <nvanfalk at gmail.com>
  • Date: Wed, 21 Sep 2011 05:35:41 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201109160948.FAA12399@smc.vnet.net> <j548vf$63h$1@smc.vnet.net>

On Sep 18, 1:09 am, Heike Gramberg <heike.gramb... at gmail.com> wrote:
> You could try something like
>
> totlist[lists__List] := Module[{jlist = Join[lists], dates},
>   dates = DeleteDuplicates[jlist[[All, 1]]];
>   Transpose[{dates, Total[Cases[jlist, {#, a_} :> a]] & /@ dates}]]
>
> usage:
>
> list1 = {{{2011, 9, 16, 0, 0, 0}, a}, {{2010, 10, 30, 0, 0, 0}, b}, {{2009, 7, 5, 0, 0, 0}, c}};
> list2 = {{{2011, 9, 16, 0, 0, 0}, 1}, {{2010, 08, 15, 0, 0, 0}, 2}, {{2009, 4, 29, 0, 0, 0}, 3}};
> totlist[list1, list2]
>
> output:
>
> {{{2011, 9, 16, 0, 0, 0}, 1 + a}, {{2010, 10, 30, 0, 0, 0}, b},
>  {{2009, 7, 5, 0, 0, 0}, c}, {{2010, 8, 15, 0, 0, 0}, 2},
>  {{2009, 4, 29, 0, 0, 0}, 3}}
>
> Heike
>
> On 16 Sep 2011, at 11:48, Nguyen Van Falk wrote:
>
>
>
>
>
>
>
> > I am trying to add multiple lists together and am looking for some
> > guidance. My data is in the form of multiple time series, with dates
> > that overlap one another. I need to merge the lists, add all of the
> > values together  for the dates that overlap and output a single list
> > that only has one entry for each date.
>
> > For example, if I have three values for September 15 (8,14,10), I only
> > want a single entry for September 15 in the final list with a value of
> > 32. The data is in standard date spec form: { {{Date 1}, Value 1},
> > {{Date 2}, Value 2},  {{Date 3}, Value 3}, ....... {{Date n}, Value
> > n}, }.
>
> > Thanks,
>
> > NVF

Thank you for the suggestions everyone.




  • Prev by Date: Re: Numbers get all squished
  • Next by Date: Re: Problem in "block cutting"
  • Previous by thread: Re: List Manipulation- Advanced beginner question
  • Next by thread: Re: List Manipulation- Advanced beginner question