Method: Enumerable#mean_stdev
- Defined in:
- ext/enumerable/statistics/extension/statistics.c
#mean_stdev(population: false) ⇒ mean, stdev
Calculate a mean and a standard deviation of the values in enum.
The first element of the result array is the mean,
and the second is the standard deviation.
This method is equivalent to:
def mean_stdev(population: false)
m, v = mean_variance(population: population)
[m, Math.sqrt(v)]
end
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 |
# File 'ext/enumerable/statistics/extension/statistics.c', line 1523
static VALUE
enum_mean_stdev(int argc, VALUE* argv, VALUE obj)
{
struct variance_opts options;
VALUE opts, mean, variance;
size_t ddof = 1;
rb_scan_args(argc, argv, "0:", &opts);
get_variance_opts(opts, &options);
if (options.population)
ddof = 0;
enum_mean_variance(obj, &mean, &variance, ddof);
VALUE stdev = sqrt_value(variance);
return rb_assoc_new(mean, stdev);
}
|