Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5037
| From | Heike Gramberg <heike.gramberg@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: List Manipulation- Advanced beginner question |
| Date | 2011-09-18 08:09 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j548vf$63h$1@smc.vnet.net> (permalink) |
| 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
>
Back to comp.soft-sys.math.mathematica | Previous | Next — Next in thread | Find similar | Unroll thread
Re: List Manipulation- Advanced beginner question Heike Gramberg <heike.gramberg@gmail.com> - 2011-09-18 08:09 +0000 Re: List Manipulation- Advanced beginner question Nguyen Van Falk <nvanfalk@gmail.com> - 2011-09-21 09:43 +0000
csiph-web