avg

The avg aggregate computes the average, or mean, value of the values in each specified dimension.

Synopsis

AFL% aggregate(array,avg(attribute)[,dimension_1,dimension_2,...]

Summary

The avg aggregate computes the average, or mean, value of the values in each specified dimension.

Rules for empty cells and NULL values.

  • avg of an empty array is NULL.
  • avg of an attribute dimension that contains only NULL values is  NULL.
  • avg of an attribute dimension that has some non-NULL values is the average of the non-NULL values only.

Example

To find the average of the rows or columns of an array:

  1. Create an array:

    AFL% create array M <v:double>[row=0:1; col=0:1];
    AFL% store(build(M,row*2+col),M); 


    The output is:

    {row,col} v
    {0,0} 0
    {0,1} 1
    {1,0} 2
    {1,1} 3
  2. Find the average of each row:

    AFL% aggregate(M,avg(v),row) 


    The output is:

    {row} v_avg
    {0} 0.5
    {1} 2.5
  3. Find the average of each column:

    AFL% aggregate(M,avg(v),col) 


    The output is:

    {row} v_avg
    {0} 1
    {1} 2

    Â