Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: average of column

by pvaldes (Chaplain)
on Sep 12, 2012 at 18:18 UTC ( #993276=note: print w/replies, xml ) Need Help??


in reply to average of column

Arg, that's very similar to the other solutions but not so elegant. Well... another way to skin this cat

#!/usr/bin/perl use strict; use warnings; use List::Util qw(sum); my @array = (); while (<DATA>) { next if /start/; chomp; my (undef,undef,undef,$col4,undef) = split (/\s*/, $_,5); push (@array, $col4); } my $sum = sum(@array); print $sum,"\/"; my $n = scalar(@array); print $n,"\n"; print "average = ", $sum/$n,"\n"; __DATA__ chr start end length foo e r t 6 r 4 A 6 4 f 4 3 4 5 f L 0 L 2 f 0 0 0 1 0 3 4 5 6 7

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993276]
help
Chatterbox?
[LanX]: ;)
[Discipulus]: good night monks!
[shmem]: LanX: oh... now I have to figure out if this is good or bad news.
LanX bad day monks ?
[LanX]: hope you find sleep
[shmem]: LanX: which one?
[LanX]: the last
Discipulus yes a very bad day
[shmem]: grandola, vila morena
[shmem]: LanX: ah, that one. You'll get the bug reports also :P

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-04-29 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (534 votes). Check out past polls.