thirtysixthspan / descriptive_statistics

MIT License
755 stars 69 forks source link

Median of an array with only one element fails #24

Closed sven-strothoff closed 10 years ago

sven-strothoff commented 10 years ago

Calculating the median of an array with only a single element fails. The median code uses percentile(50) and that crashes if there are not al least two elements.

I know that it makes little sense to calculate the median of a single element, however, I use the desctiptive_statistics gem to do batch processing of large amounts of data and process arrays with lengths from 1 to n.

While I can handle that case in my code, I think that others would also benefit if median would work for one element.

thirtysixthspan commented 10 years ago

Thanks! I've updated the code and tests to cover that case in version 2.0.1. Your input is much appreciated. I would love to hear more of how you use the gem.