lib/basic/stats.rb in basic-stats-0.0.1 vs lib/basic/stats.rb in basic-stats-0.0.2

- old
+ new

@@ -8,9 +8,15 @@ def mean self.sum/self.length.to_f end + def median + sorted = self.sort + len = sorted.length + return (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0 + end + def sample_variance m = self.mean sum = self.inject(0){|accum, i| accum +(i-m)**2 } sum/(self.length - 1).to_f end