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

MathGroup Archive 2009

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

Search the Archive

Re: compress lists with mean for equal elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101032] Re: compress lists with mean for equal elements
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sun, 21 Jun 2009 07:07:21 -0400 (EDT)
  • References: <h1hbfr$n4$1@smc.vnet.net>

Hi,

data = {{{1, 13}, 97.6493}, {{1, 13}, 97.9511}, {{1, 14},
    99.3002}, {{1, 14}, 99.4602}, {{1, 14}, 99.6193}, {{1, 15},
    100.513}, {{1, 15}, 101.149}, {{1, 15}, 101.483}, {{1, 15},
    101.494}, {{1, 16}, 101.51}, {{1, 16}, 101.895}};

and

{#, Mean[Last /@ Cases[data, {#, _}, Infinity]]} & /@
  Union[First /@ data]

?

Regards
   Jens

vJD wrote:
> I have a nested list of this form:
> 
> {{{1, 13}, 97.6493}, {{1, 13}, 97.9511}, {{1, 14}, 99.3002}, {{1, 14},
> 99.4602}, {{1, 14}, 99.6193}, {{1, 15}, 100.513}, {{1, 15}, 101.149},
> {{1, 15}, 101.483}, {{1, 15}, 101.494}, {{1, 16}, 101.51}, {{1, 16},
> 101.895}}
> 
> I want to shrink the list in the way that I calculate the mean over
> the second part for all elements where the first part is equal. so
> e.g. the first element of the new list will be {{1,13}, 97.8002},
> because they both have {1,13} and the mean of 97.6493 and 97.9511 is
> 97.8002.
> 
> The problem is that there is no fixed number for the equal elements
> (so e.g. two elements with {1,13}, three elements with {1,14} and so
> on). The number is random.
> 
> Can anybody please provide me with a statement or hint how to
> accomplish that task.
> 
> Thank you very much
> 
> Regards,
> Holger
> 


  • Prev by Date: Re: compress lists with mean for equal elements
  • Next by Date: Re: Slow performance gathering property data from fitted objects
  • Previous by thread: Re: compress lists with mean for equal elements
  • Next by thread: BarChart and Ticks