in reply to
Mean and standard deviation loop
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