Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5037 > unrolled thread

Re: List Manipulation- Advanced beginner question

Started byHeike Gramberg <heike.gramberg@gmail.com>
First post2011-09-18 08:09 +0000
Last post2011-09-21 09:43 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#5037 — Re: List Manipulation- Advanced beginner question

FromHeike Gramberg <heike.gramberg@gmail.com>
Date2011-09-18 08:09 +0000
SubjectRe: List Manipulation- Advanced beginner question
Message-ID<j548vf$63h$1@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
>

[toc] | [next] | [standalone]


#5127

FromNguyen Van Falk <nvanfalk@gmail.com>
Date2011-09-21 09:43 +0000
Message-ID<j5cbjg$d2q$1@smc.vnet.net>
In reply to#5037
On Sep 18, 1:09 am, Heike Gramberg <heike.gramb...@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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web