What data structure do you have the data in? That will determine the details of how to do this.

Lets suppose you can get a column as a list (not necessarily an array). You can grep to remove db NULL's, which are undef in perl, and use references to the data to do something like this.

# $data is a hashref, a standin for the data struct you have my @ranks = \(grep {defined} values %$data); my $idx = 0; $$_ = ++$idx for sort {$$a <=> $$b} @ranks; # step 1 & 2 $$_ /= $idx for @ranks; # step 3
The values are changed in place in the original data structure because we work with references to those locations. Division by zero is avoided because for over an empty list never does a division.

After Compline,
Zaxo


In reply to Re: converting list of rankings into list of rankratio's. by Zaxo
in thread converting list of rankings into list of rankratio's. by BioGeek

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.