Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg121500] Re: List Manipulation- Advanced beginner question
  • From: Heike Gramberg <heike.gramberg at gmail.com>
  • Date: Sun, 18 Sep 2011 04:08:23 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201109160948.FAA12399@smc.vnet.net>

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
>





  • Prev by Date: Eliminate works but Solve does not?
  • Next by Date: Re: Making a function from the output of the Fit function.
  • Previous by thread: Re: List Manipulation- Advanced beginner question
  • Next by thread: Re: List Manipulation- Advanced beginner question