Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: optimize percentile counting in hash

by max210 (Novice)
on Mar 21, 2008 at 01:36 UTC ( [id://675356]=note: print w/replies, xml ) Need Help??


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

Thanks for trying to help me out. I really appreciate it :)

I was not using \<code\></code> may be that's y u had error. The code should work now. I HAVE TO FIND PERCENTILE AND NOT PERCENTAGE :( which makes it more difficult to execute in less time.

Eagerly waiting for reply, thanks again
  • Comment on Re^2: optimize percentile counting in hash

Replies are listed 'Best First'.
Re^3: optimize percentile counting in hash
by ikegami (Patriarch) on Mar 21, 2008 at 01:56 UTC
    How about
    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) { $total += $count{$datum}; $percentile{$datum} = $total / @data; }

      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

        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}; }
Re^3: optimize percentile counting in hash
by apl (Monsignor) on Mar 21, 2008 at 02:24 UTC
    For future reference, if you modify your original post, you should also add a Revised: note, explaining the change. Otherwise it's confusing to the people new to the thread.
      sorry, got logged out and posted msg as anonym.... the formula for percentile is given by me, sorry for confusion...... plz help
      will keep that in mind, thanks :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2024-04-16 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found