4
$\begingroup$

This seems like something I should be able to do but I can not for the life of me figure it out. I'm writing a program to calculate an average score; let's say that my data looks like this.

x = number of votes

y = current rating

z = new rating

Is there a way for me to calculate in the new rating, without needing the scores of each individual vote?

So say that an item has a total of two scores, the data would look like this:

x = 2

y = 90

and then a new rating is introduced (let's say someone scored a 50%):

z = 50

I need to calculate how the z would influence the 90%, without having a record of each individual rating.

Help is greatly appreciated!

$\endgroup$

1 Answer 1

3
$\begingroup$

Suppose that $x$ votes lead to rating of $y$. Then $xy$ is the current total score (the sum of the scores of the $x$ people). Add the new score $z$, and divide by the new number of people. So the new average is $$\frac{xy+z}{x+1}.$$

In your numerical example, we have $x=2$ and the average score is $90$. So the scores of the $2$ people add up to $(2)(90)=180$. Add the new score $50$. We get $230$. Finally, divide by $3$.

Remark: The letters $x$, $y$, and $z$ are perhaps not ideal for your problem. I would call the current number of people something like $n$ instead of $x$.

$\endgroup$
1
  • $\begingroup$ Thank you so much! This answered it perfectly. Waiting until I can accept it as an answer. I was just using those variables as placeholders (in the code, they're described by their variable names). $\endgroup$ Commented Dec 2, 2012 at 18:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .