Module: Enumerable

Defined in:
lib/tabula/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#meanObject



23
24
25
# File 'lib/tabula/core_ext.rb', line 23

def mean
  self.sum/self.length.to_f
end

#sample_varianceObject



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

Returns:

  • (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_deviationObject



33
34
35
# File 'lib/tabula/core_ext.rb', line 33

def standard_deviation
  return Math.sqrt(self.sample_variance)
end

#sumObject



19
20
21
# File 'lib/tabula/core_ext.rb', line 19

def sum
  self.inject(0){|accum, i| accum + i }
end