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}; }