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


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

Re: List Manipulation- Advanced beginner question

Started byBill Rowe <readnews@sbcglobal.net>
First post2011-09-17 10:28 +0000
Last post2011-09-17 10:28 +0000
Articles 1 — 1 participant

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


Contents

  Re: List Manipulation- Advanced beginner question Bill Rowe <readnews@sbcglobal.net> - 2011-09-17 10:28 +0000

#5019 — Re: List Manipulation- Advanced beginner question

FromBill Rowe <readnews@sbcglobal.net>
Date2011-09-17 10:28 +0000
SubjectRe: List Manipulation- Advanced beginner question
Message-ID<j51so4$pf5$1@smc.vnet.net>
On 9/16/11 at 5:48 AM, nvanfalk@gmail.com (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}, }.

First generate some data in the form you describe:

In[7]:= data =
  Join[{{9, 15, 2011}, #} & /@ {8, 14, 10}, {{8, 15, 2011}, #} & /@
    RandomInteger[50, 4]]

Out[7]= {{{9, 15, 2011}, 8}, {{9, 15, 2011}, 14}, {{9, 15,
2011}, 10},
    {{8, 15, 2011}, 24}, {{8, 15, 2011}, 12}, {{8, 15, 2011}, 32},
    {{8, 15, 2011}, 33}}

then sum per date as follows:

In[8]:= {#[[1, 1]], Total[#[[All, 2]]]} & /@ GatherBy[data, First]

Out[8]= {{{9, 15, 2011}, 32}, {{8, 15, 2011}, 101}}

[toc] | [standalone]


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


csiph-web