Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/conductor.rb
Instance Method Summary collapse
Instance Method Details
#sum_it(attribute) ⇒ Object
93 94 95 |
# File 'lib/conductor.rb', line 93 def sum_it(attribute) self.map {|x| x.send(attribute) }.compact.sum end |
#weighted_mean ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/conductor.rb', line 101 def weighted_mean w_sum = sum(self) return 0.00 if w_sum == 0.00 w_prod = 0 self.each_index {|i| w_prod += (i+1) * self[i].to_f} w_prod.to_f / w_sum.to_f end |
#weighted_mean_of_attribute(attribute) ⇒ Object
97 98 99 |
# File 'lib/conductor.rb', line 97 def weighted_mean_of_attribute(attribute) self.map {|x| x.send(attribute) }.compact.weighted_mean end |