If you have any problems or questions, please let me know.
Thanks.
Wags ;)
David R Wagner
Senior Programmer Analyst
FedEx Freight
1.408.323.4225x2224 TEL
1.408.323.4449 FAX
http://fedex.com/us
> -----Original Message-----
> From: Mahurshi Akilla [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, October 03, 2007 11:18
> To: [email protected]
> Subject: average and standard deviation
>
> is there an easy way to get the average and standard deviation in perl
> (given an array of numbers). i don't want to reinvent the wheel and
> write my own functions.
>
> i saw something for the average (see below). it works fine. is there
> a similar quickie for std deviation (or perhaps, the median)
>
> use List::Util qw(sum);
> @array = (1, 1.5, 2);
> $average = sum(@array)/@array;
> print "$average
>
>
You did not state which OS you are running and assuiming you can load
modules, but from ActivePerl for Windows (also on CPAN )
Statistics::Descriptive ( Loaded and took the example from the doc and
ran):
#!perl
use strict;
use warnings;
use Statistics::Descriptive;
my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(1, 1.5, 2);
my $mean = $stat->mean();
my $var = $stat->variance();
my $tm = $stat->trimmed_mean(.25);
my $std = $stat->standard_deviation();
$Statistics::Descriptive::Tolerance = 1e-10;
printf "Mean: %10.4f Var: %10.4f Std Dev: %10.4f Trimmed mean:
%10.4f\n",
$mean,
$var ,
$std ,
$tm ;
Output:
Mean: 1.5000 Var: 0.2500 Std Dev: 0.5000 Trimmed mean:
1.5000
Wags ;)
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>
**********************************************************************
This message contains information that is confidential and proprietary to FedEx
Freight or its affiliates. It is intended only for the recipient named and for
the express purpose(s) described therein. Any other use is prohibited.
**********************************************************************
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/