Created
January 7, 2013 09:39
-
-
Save redroot/4473719 to your computer and use it in GitHub Desktop.
Weighted Mean - Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # array of arrays | |
| a = [[10, 1000], [9, 923], [8, 1230], [7, 10]] # [data,frequency] | |
| mean = a.reduce(0) { |m,r| m += r[0] * r[1] } / a.reduce(0) { |m,r| m += r[1] }.to_f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment