class DataSumz::Frequency
Attributes
data[R]
Public Class Methods
new(_data)
click to toggle source
# File lib/datasumz/frequency.rb, line 10 def initialize(_data) @data = _data end
Public Instance Methods
compute()
click to toggle source
# File lib/datasumz/frequency.rb, line 14 def compute table = Hash.new(Array.new) total = @data.length hist = @data.each_with_object(Hash.new(0)){ |m,h| h[m] += 1 }.sort_by{ |k,v| v } hist.each do |bin| name = bin[0] n = bin[1] per_total = ((n.to_f / total.to_f) * 100).round(2) table[name] = [n, per_total] end table end