Month,Zone,Replicate,SpeciesA,SpeciesB,SpeciesC
Sept,1,1,5,10,15
Sept,1,2,0,5,10
Sept,1,3,5,0,5
Sept,2,1,5,5,5
Sept,2,2,10,15,10
Sept,2,3,0,0,5
####
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Table;
use Statistics::Lite qw(mean stddev);
my $dt = Data::Table::fromCSV("data.csv");
print "Original Data Table\n";
print "===================\n";
print $dt->tsv;
print "\n\n";
my $melt = $dt->melt(['Month', 'Zone', 'Replicate']);
print "Melt Table\n";
print "==========\n";
print $melt->tsv;
print "\n\n";
my $cast_mean = $melt->cast(
['Month', 'Zone'],
'variable',
Data::Table::STRING,
'value',
\&mean
);
print "Cast (mean)\n";
print "===========\n";
print $cast_mean->tsv;
print "\n\n";
my $cast_stddev = $melt->cast(
['Month', 'Zone'],
'variable',
Data::Table::STRING,
'value',
\&stddev
);
print "Cast (stddev)\n";
print "=============\n";
print $cast_stddev->tsv;
exit;
####
Original Data Table
===================
Month Zone Replicate SpeciesA SpeciesB SpeciesC
Sept 1 1 5 10 15
Sept 1 2 0 5 10
Sept 1 3 5 0 5
Sept 2 1 5 5 5
Sept 2 2 10 15 10
Sept 2 3 0 0 5
Melt Table
==========
Month Zone Replicate variable value
Sept 1 1 SpeciesA 5
Sept 1 1 SpeciesB 10
Sept 1 1 SpeciesC 15
Sept 1 2 SpeciesA 0
Sept 1 2 SpeciesB 5
Sept 1 2 SpeciesC 10
Sept 1 3 SpeciesA 5
Sept 1 3 SpeciesB 0
Sept 1 3 SpeciesC 5
Sept 2 1 SpeciesA 5
Sept 2 1 SpeciesB 5
Sept 2 1 SpeciesC 5
Sept 2 2 SpeciesA 10
Sept 2 2 SpeciesB 15
Sept 2 2 SpeciesC 10
Sept 2 3 SpeciesA 0
Sept 2 3 SpeciesB 0
Sept 2 3 SpeciesC 5
Cast (mean)
===========
Month Zone SpeciesA SpeciesB SpeciesC
Sept 1 3.33333333333333 5 10
Sept 2 5 6.66666666666667 6.66666666666667
Cast (stddev)
=============
Month Zone SpeciesA SpeciesB SpeciesC
Sept 1 2.88675134594813 5 5
Sept 2 5 7.63762615825973 2.88675134594813