1Statistics::Basic::MediUasne(r3)Contributed Perl DocumenSttaattiiosntics::Basic::Median(3)
2
3
4
6 Statistics::Basic::Median - find the median of a list
7
9 Invoke it this way:
10
11 my $median = median(1,2,3);
12
13 Or this way:
14
15 my $v1 = vector(1,2,3);
16 my $med = median($v1);
17
18 And then either query the values or print them like so:
19
20 print "The median of $v1: $med\n";
21 my $mq = $med->query;
22 my $m0 = 0+$med;
23
24 Create a 20 point "moving" median 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 $med = median()->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 $med->insert( $val );
37 if( defined( $m = $med->query ) ) {
38 print "Median: $m\n";
39 }
40
41 # This would also work:
42 # print "Median: $med\n" if $med->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::Median object.
50
51 Note: normally you'd use the median() 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.1 2021-01-27 Statistics::Basic::Median(3)