Re: Summing over like elements
- To: mathgroup at smc.vnet.net
- Subject: [mg13881] Re: Summing over like elements
- From: mefisher at my-dejanews.com
- Date: Sun, 6 Sep 1998 02:55:21 -0400
- Organization: Deja News - The Leader in Internet Discussion
- References: <6sdb8i$peq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Here is something that will work. I don't know how efficient it is.
list={{1, .5} , {2, .2} , {1, .1}}
Apply[{First[#1], Plus @@ #2}&, Transpose[#]]& /@
Split[Sort[list], First[#1] == First[#2]&]
--Mark.
In article <6sdb8i$peq at smc.vnet.net>,
"Mitchell Kaplan" <qmak at pipeline.com> wrote:
> I have a 2 column array. Column 1 has some values, many of which are
> repeated. Column 2 has probabilities of these values.
>
> I would like to sum the probabilities for each unique element in column
> 1. For example:
>
> {{1, .5} , {2, .2} , {1, .1}} should give me:
>
> {{1, .6} , {2, .2}}
>
> I'm sure I can do this with a "Do" loop -- however it seems that in
> general "Do's" are pretty innefficient.
>
> Does anyone have any suggestions?
>
> Mitch
>
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum