Module: Enumerable
- Defined in:
- lib/tabula/core_ext.rb
Instance Method Summary collapse
- #mean ⇒ Object
- #sample_variance ⇒ Object
- #sorted? ⇒ Boolean
- #standard_deviation ⇒ Object
- #sum ⇒ Object
Instance Method Details
#mean ⇒ Object
23 24 25 |
# File 'lib/tabula/core_ext.rb', line 23 def mean self.sum/self.length.to_f end |
#sample_variance ⇒ Object
27 28 29 30 31 |
# File 'lib/tabula/core_ext.rb', line 27 def sample_variance m = self.mean sum = self.inject(0) {|accum, i| accum + (i-m)**2 } sum/(self.length - 1).to_f end |
#sorted? ⇒ Boolean
37 38 39 |
# File 'lib/tabula/core_ext.rb', line 37 def sorted? each_cons(2).all? { |a, b| (a <=> b) <= 0 } end |
#standard_deviation ⇒ Object
33 34 35 |
# File 'lib/tabula/core_ext.rb', line 33 def standard_deviation return Math.sqrt(self.sample_variance) end |
#sum ⇒ Object
19 20 21 |
# File 'lib/tabula/core_ext.rb', line 19 def sum self.inject(0){|accum, i| accum + i } end |