Skip to content

Instantly share code, notes, and snippets.

@redroot
Created January 7, 2013 09:39
Show Gist options
  • Select an option

  • Save redroot/4473719 to your computer and use it in GitHub Desktop.

Select an option

Save redroot/4473719 to your computer and use it in GitHub Desktop.
Weighted Mean - Ruby
# 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