I have several records with a given attribute, and I want to find the standard deviation.
How do I do that?
As a simple function, given a list of numbers:
def standard_deviation(list) mean = list.inject(:+) / list.length.to_f var_sum = list.map{|n| (n-mean)**2}.inject(:+).to_f sample_variance = var_sum / (list.length - 1) Math.sqrt(sample_variance) end