Re: Average the same elements of the list

• To: mathgroup at smc.vnet.net
• Subject: [mg130896] Re: Average the same elements of the list
• From: Daniel <dosadchy at its.jnj.com>
• Date: Fri, 24 May 2013 06:23:17 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net

```data={{{a1,b1,c1},d1},{{a2,b2,c2},d2}};
{#[[1, 1]], #[[All, 2]] // Mean} & /@ SplitBy[data, First]

output:
{{{a1, b1, c1}, d1}, {{a2, b2, c2}, d2}}

data={{{a1,b1,c1},d1},{{a1,b1,c1},d2}};
{#[[1, 1]], #[[All, 2]] // Mean} & /@ SplitBy[data, First]

output:
{{{a1, b1, c1}, (d1 + d2)/2}}

> Hello,
> I have list which is something like
> data={
> {{a1,b1,c1},d1},{{a2,b2,c2},d2}}
> I would like to get new list which gets average of
> the second elements if the first elements in the
> sublists are all the same.
> Namely if a1=a2,b1=b2,c1=c2
> new list would look like
> datanew={{a1,b1,c1},Mean[{d1,d2}]
> Is there an elegant way to do this ?
> Thanks!
>

```

• Prev by Date: Re: Comment about SetDirectory[]
• Next by Date: Re: How to stretch a image
• Previous by thread: Re: Average the same elements of the list
• Next by thread: ListPlot skips first point