1Statistics::Basic::MeanU(s3e)r Contributed Perl DocumentaSttiaotnistics::Basic::Mean(3)
2
3
4
6 Statistics::Basic::Mean - find the mean of a list
7
9 Invoke it this way:
10
11 my $avg = mean(1,2,3);
12
13 Or this way:
14
15 my $v1 = vector(1,2,3);
16 my $avg = avg($v1);
17
18 And then either query the values or print them like so:
19
20 print "The mean of $v1: $avg\n";
21 my $mq = $avg->query;
22 my $m0 = 0+$avg;
23
24 Create a 20 point moving average like so:
25
26 use Statistics::Basic qw(:all nofill);
27
28 my $sth = $dbh->prepare("select col1 from data where something");
29 my $len = 20;
30 my $avg = mean()->set_size($len);
31
32 $sth->execute or die $dbh->errstr;
33 $sth->bind_columns( my $val ) or die $dbh->errstr;
34
35 while( $sth->fetch ) {
36 $avg->insert( $val );
37 if( defined( my $m = $avg->query ) ) {
38 print "Mean: $m\n";
39 }
40
41 # This would also work:
42 # print "Mean: $avg\n" if $avg->query_filled;
43 }
44
46 new()
47 The constructor takes a single array ref or a single
48 Statistics::Basic::Vector as arguments. It returns a
49 Statistics::Basic::Mean object.
50
51 Note: normally you'd use the mean() constructor, rather than
52 building these by hand using "new()".
53
54 _OVB::import()
55 This module also inherits all the overloads and methods from
56 Statistics::Basic::_OneVectorBase.
57
59 This object is overloaded. It tries to return an appropriate string
60 for the calculation or the value of the computation in numeric context.
61
62 In boolean context, this object is always true (even when empty).
63
65 Paul Miller "<jettero@cpan.org>"
66
68 Copyright 2012 Paul Miller -- Licensed under the LGPL
69
71 perl(1), Statistics::Basic, Statistics::Basic::_OneVectorBase,
72 Statistics::Basic::Vector
73
74
75
76perl v5.32.0 2020-07-28 Statistics::Basic::Mean(3)