Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I was tempted to go for a Fortran web service with SQL (http://fortran.io), but I settled for a solution using Data::Table.

#!/usr/bin/env perl use strict; use warnings; use Data::Table; # Giving '0' as the second arg to Data::Table::fromTSV, # results in a Data::Table with column names of col1, col2 and col3 my $t = Data::Table::fromTSV("data.tsv", 0); my $nrow = $t->nofRow; my @row_numbers = 1..$nrow; # Sort by 'col2' as numeric values in decending order $t->sort( 'col2', 0, 1 ); # Add a new column that contains the row indices for the 'col2' sort o +rder $t->addCol( \@row_numbers, 'col2order' ); # Sort by 'col3' as numeric values in decending order $t->sort( 'col3', 0, 1 ); # Add a new column that contains the row indices for the 'col3' sort o +rder $t->addCol( \@row_numbers, 'col3order' ); # Sort by 'col1' as string values in ascending order $t->sort( 'col1', 1, 0 ); # Get a subtable with the columns of interest my $result = $t->subTable( undef, [ 'col1', 'col2order', 'col3order' ] + ); print $result->tsv; exit;
This input is in data.tsv:
a 23 11 b 24 15 c 16 19 d 8 2 e 40 41
The output is:
col1 col2order col3order a 3 4 b 2 3 c 4 2 d 5 5 e 1 1

In reply to Re^3: manipulating a data table by kevbot
in thread manipulating a data table by v15

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-03-28 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found