in reply to summary statistics using Data::Table
#! /usr/bin/perl use warnings; use strict; use List::Util qw{ sum }; use Data::Table; my $t = new Data::Table( [ ['a', 1000, 2000, 3000, 200,500], ['b', 2000, 1000, 1000, 700,800], ['c', 3000, 3000, 3000, 5,7], ], ['Name', 'value1', 'value2', 'value3', 'value4', 'value5'], 0); $t->addCol(undef, 'v1-3'); $t->colsMap(sub { $_->[-1] = sum(@$_[1 .. 3]) / 3 }); $t->addCol(undef, 'v4,5'); $t->colsMap(sub { $_->[-1] = sum(@$_[4, 5]) / 2 }); print $t->csv;
Or, more DRY:
sub set_avg { my @cols = @_; sub { $_->[-1] = sum(@$_[@cols]) / @cols } } $t->addCol(undef, 'v1-3'); $t->colsMap(set_avg(1 .. 3)); $t->addCol(undef, 'v4,5'); $t->colsMap(set_avg(4, 5));
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: summary statistics using Data::Table
by sisterdot (Initiate) on Dec 14, 2015 at 07:56 UTC |