This could also easily be solved using DBI to calculate the averages. If you are familiar with SQL, this could be a possible solution.
#!/usr/bin/perl use strict; use warnings; use Text::Table; use DBI; my $dbh = DBI->connect("DBI:CSV:"); $dbh->{'csv_tables'}->{'data'} = { 'file' => 'junk.txt'}; my $sql = <<SQL; select Col1, Col3, AVG(Col4), AVG(Col5), AVG(Col6) from data group by Col1, Col3 order by Col1, Col3 SQL my $sth = $dbh->prepare( $sql ); $sth->execute; my $tb = Text::Table->new(qw/ Col1 Col3 Avg_Col4 Avg_Col5 Avg_Col6 /); while ( my $row = $sth->fetchrow_arrayref ) { $tb->load($row); } print $tb; __END__ C:\Old_Data\perlp>perl t.pl Col1 Col3 Avg_Col4 Avg_Col5 Avg_Col6 Name 1 ID 1 0.53750595725 0.66002015475 0.373256641 Name 1 ID 2 0.503016916125 0.6786437965 0.556675151625 Name 1 ID 3 0.36942296675 0.445537553 0.386080953375 Name 2 ID 1 0.516050550333333 0.3745506395 0.337977443166667 Name 2 ID 2 0.559323705444444 0.376110070666667 0.362031394222222 Name 2 ID 3 0.415733165 0.5957284203 0.4376514411 Name 2 ID 4 0.5109963958 0.492942305933333 0.669402401266667 Name 2 ID 5 0.547109591375 0.5205764764375 0.605138018875 Name 2 ID 6 0.5141908028 0.378785432866667 0.492416377133333 Name 3 ID 1 0.440476683375 0.600837193125 0.356844589375 Name 3 ID 2 0.503670895181818 0.558365503181818 0.471884158818182 Name 3 ID 3 0.460990542307692 0.487847332692308 0.347110462153846 Name 3 ID 4 0.502672743615385 0.629029938307692 0.652826947307692 Name 3 ID 5 0.485902119727273 0.350142792181818 0.519689121454545 Name 3 ID 6 0.554161077076923 0.544737969461538 0.565414750615385 Name 3 ID 7 0.564178885230769 0.604259375076923 0.369545730769231 Name 3 ID 8 0.5017849838 0.3991158152 0.515273186

Chris


In reply to Re: Mean and standard deviation loop by Cristoforo
in thread Mean and standard deviation loop by SixShot

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.