Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max and Min Gives Misleading Data #40

Open
tra38 opened this issue Feb 27, 2016 · 0 comments
Open

Max and Min Gives Misleading Data #40

tra38 opened this issue Feb 27, 2016 · 0 comments

Comments

@tra38
Copy link

tra38 commented Feb 27, 2016

require 'descriptive_statistics'
hash = {:a=>2,:b=>6,:c=>9,:d=>3,:e=>5,:f=>1,:g=>8,:h=>3,:i=>6,:j=>9,:k=>2}
hash.min
#=> [:a, 2]
hash.min_by { | key, value | value }
#=> [:f, 1]

hash.max
#=> [:k, 2]
hash.max_by { | key, value | value }
#=> [:c, 9]

This gem is using the native "Ruby" max and min functions, which don't really work well for Hashes (it defaults to finding the maximum and minimum keys, which is a fairly useless piece of trivia...most of the time, we don't care about alphabetical order). While you can get the correct answers by using the max_by or min_by methods that is also within native Ruby, this little "feature" can get pretty annoying when you decide to use this Ruby gem's descriptive_statistics method.

hash.descriptive_statistics
#=>
{:number=>11.0, 
:sum=>54.0, 
:variance=>7.7190082644628095, 
:standard_deviation=>2.778310325442932, 
:min=>[:a, 2],
:max=>[:k, 2],
:mean=>4.909090909090909,
:mode=>2,
:median=>5.0,
:range=>8.0,
:q1=>2.5,
:q2=>5.0,
:q3=>7.0}

I don't really know of a good way to fix this annoyance, which is why I am reporting this issue to you. At the very least, having this issue here is a great way to prevent future people from getting annoyed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant