Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: optimize percentile counting in hash

by Anonymous Monk
on Mar 21, 2008 at 02:27 UTC ( [id://675361]=note: print w/replies, xml ) Need Help??


in reply to Re^3: optimize percentile counting in hash
in thread optimize percentile counting in hash

its giving incorrect percentile values :( to find percentile rank of score x out of n scores:
(number of scores below x)/n*100 = percentile rank
need to sort the hash first, i used index value of the array to find number of scores below x. x is value of hash taken one by one and returning the percentile

  • Comment on Re^4: optimize percentile counting in hash

Replies are listed 'Best First'.
Re^5: optimize percentile counting in hash
by ikegami (Patriarch) on Mar 21, 2008 at 02:40 UTC
    oh, below, not below or equal. Just switch the order of the two statements in the last loop. I usually only do the *100 when it's time to print, but I added it for you.
    use strict; use warnings; my @data = get_data(); # or however you get them my %count; foreach my $datum (@data) { ++$count{$datum}; } my %percentile; my $total = 0; foreach my $datum (sort { $a <=> $b } keys %count) { $percentile{$datum} = $total / @data * 100; $total += $count{$datum}; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://675361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found