Method: Rust::Descriptive.mean

Defined in:
lib/rust/stats/descriptive.rb

.mean(data) ⇒ Object

Computes the arithmetic mean of the given data.

Raises:

  • (TypeError)


12
13
14
15
16
# File 'lib/rust/stats/descriptive.rb', line 12

def mean(data)
    raise TypeError, "Expecting Array of numerics" if !data.is_a?(Array) || !data.all? { |e| e.is_a?(Numeric) }
    
    return data.sum.to_f / data.size
end