Class: DataSumz::Frequency
- Inherits:
-
Object
- Object
- DataSumz::Frequency
- Defined in:
- lib/datasumz/frequency.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#compute ⇒ Object
def initialize.
-
#initialize(_data) ⇒ Frequency
constructor
A new instance of Frequency.
Constructor Details
#initialize(_data) ⇒ Frequency
Returns a new instance of Frequency.
10 11 12 |
# File 'lib/datasumz/frequency.rb', line 10 def initialize(_data) @data = _data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/datasumz/frequency.rb', line 6 def data @data end |
Instance Method Details
#compute ⇒ Object
def initialize
14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |