MathGroup Archive 1998

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

Search the Archive

Re: Summing over like elements

  • To: mathgroup at
  • Subject: [mg13861] Re: [mg13855] Summing over like elements
  • From: "Richard Finley" <rfinley at>
  • Date: Wed, 2 Sep 1998 01:30:56 -0400
  • Sender: owner-wri-mathgroup at


Here is a quick and easy little function that should work:

flist_ : Sortlist //.
x___,a_,b_,a_,c_,y___ÿ-> x,a,b+c,y

Note that the blanks after the x and the y are triple blanks (to account
 for null positions). Of course,
there is no error checking to ensure that your probabilities don't sum
 to more than one 

Regards,  RF

Richard Finley, M.D.

>>> Mitchell Kaplan <> 08/30 11:09 PM >>>
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?


  • Prev by Date: WHere can I get good mathematica notebooks in the web?
  • Next by Date: Re: NDSolve
  • Previous by thread: Re: Summing over like elements
  • Next by thread: Re: Summing over like elements