in reply to Re^4: Descriptive Stats from .csv file
in thread Descriptive Stats from .csv file
$ cat melt.tsv 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 $ cat melt.pl #!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use DBI; use DBD::CSV; my $dbh = DBI->connect( "dbi:CSV:", undef, undef, { RaiseError => 1 }, ); $dbh->{csv_tables}{melt} = { eol => "\n", sep_char => "\t", quote_char => undef, escape_char => undef, file => 'melt.tsv', col_names => [qw( Month Zone Replicate Species Specnum +)], }; my $names = $dbh->selectall_arrayref('SELECT DISTINCT species FROM mel +t'); dd( $names ); dd( shotsky => $dbh->selectall_arrayref(q{ select * from melt where Sp +ecies = ?}, { Slice => {} }, 'SpeciesB' ) ); for my $name ( @$names ){ dd( $name => $dbh->selectall_arrayref(' select Month, Zone, Species, AVG(Specnum) MEAN FROM melt WHERE melt.Species = ? ', { Slice => {} }, $name, ) ); } __END__ [["variable"], ["SpeciesA"], ["SpeciesB"], ["SpeciesC"]] ( "shotsky", [ { month => "Sept", replicate => 1, species => "SpeciesB", specnum => 10, zone => 1, }, { month => "Sept", replicate => 2, species => "SpeciesB", specnum +=> 5, zone => 1 }, { month => "Sept", replicate => 3, species => "SpeciesB", specnum +=> 0, zone => 1 }, { month => "Sept", replicate => 1, species => "SpeciesB", specnum +=> 5, zone => 2 }, { month => "Sept", replicate => 2, species => "SpeciesB", specnum => 15, zone => 2, }, { month => "Sept", replicate => 3, species => "SpeciesB", specnum +=> 0, zone => 2 }, ], ) ( ["variable"], [ { MEAN => undef, Month => undef, Species => undef, Zone => undef } +, ], ) ( ["SpeciesA"], [ { MEAN => undef, Month => undef, Species => undef, Zone => undef } +, ], ) ( ["SpeciesB"], [ { MEAN => undef, Month => undef, Species => undef, Zone => undef } +, ], ) ( ["SpeciesC"], [ { MEAN => undef, Month => undef, Species => undef, Zone => undef } +, ], )
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Descriptive Stats from <span style=
by Tux (Canon) on Feb 01, 2014 at 08:06 UTC | |
by Anonymous Monk on Feb 01, 2014 at 09:45 UTC |