My language is PHP, but the algorithm should be fairly universal.
I have an associative array of (let's say) ratings and number of times that rating has been given.
$ratings = array(
1 => 1,
2 => 3,
3 => 6,
4 => 3,
5 => 3
);
This is the equivalent of: [1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5]
, but given the numbers I'm working with, it would be quite inefficient to convert from the first form to the second.
What would be the algorithm to calculate the mean of the above numbers?