Table of Contents
mean
Table of Contents
Prototype: mean(list)
Return type: real
Description: Return the mean of the numbers in list
.
This function can accept many types of data parameters.
Arguments:
list
:string
, in the range:.*
Example:
body common control
{
bundlesequence => { "test" };
}
bundle agent test
{
vars:
# the behavior will be the same whether you use a data container or a list
# "mylist" slist => { "foo", "1", "2", "3000", "bar", "10.20.30.40" };
"mylist" data => parsejson('["foo", "1", "2", "3000", "bar", "10.20.30.40"]');
"mylist_str" string => format("%S", mylist);
"max_int" string => max(mylist, "int");
"max_lex" string => max(mylist, "lex");
"max_ip" string => max(mylist, "ip");
"min_int" string => min(mylist, "int");
"min_lex" string => min(mylist, "lex");
"min_ip" string => min(mylist, "ip");
"mean" real => mean(mylist);
"variance" real => variance(mylist);
reports:
"my list is $(mylist_str)";
"mean is $(mean)";
"variance is $(variance) (use eval() to get the standard deviation)";
"max int is $(max_int)";
"max IP is $(max_ip)";
"max lexicographically is $(max_lex)";
"min int is $(min_int)";
"min IP is $(min_ip)";
"min lexicographically is $(min_lex)";
}
Output:
R: my list is ["foo","1","2","3000","bar","10.20.30.40"]
R: mean is 502.200000
R: variance is 1497376.000000 (use eval() to get the standard deviation)
R: max int is 3000
R: max IP is 10.20.30.40
R: max lexicographically is foo
R: min int is bar
R: min IP is 1
R: min lexicographically is 1
History: Was introduced in version 3.6.0 (2014). The collecting function behavior was added in 3.9.
See also: sort()
, variance()
, sum()
, max()
, min()
, about collecting functions, and data
documentation.