Task[edit]
Write a program to find the mean (arithmetic average) of a numeric vector.

In case of a zero-length input, since the mean of an empty set of numbers is ill-defined, the program may choose to behave in any way it deems appropriate, though if the programming language has an established convention for conveying math errors or undefined values, it's preferable to follow it.

See also
Tasks for calculating statistical measures



in one go
moving (sliding window)
moving (cumulative)

Mean
Arithmetic

Statistics/Basic
Averages/Arithmetic mean
Averages/Pythagorean means


Averages/Simple moving average




Geometric

Averages/Pythagorean means




Harmonic

Averages/Pythagorean means




Quadratic

Averages/Root mean square




Circular

Averages/Mean angle
Averages/Mean time of day




Median

Averages/Median




Mode

Averages/Mode




Standard deviation

Statistics/Basic



Cumulative standard deviation






  [ $ 'bigrat.qky' loadfile ] now!
 
  [ [] swap times
    [ 20001 random 10000 -
      n->v 100 n->v v/
      join nested join ] ]   is makevector   (   --> [   )
 
  [ witheach 
      [ unpack 
        2 point$ echo$
        i 0 > if 
          [ say ", " ] ] ]   is echodecs      ( [ -->     )
 
  [ dup size n->v rot
    0 n->v rot
    witheach 
      [ unpack v+ ]
    2swap v/ ]               is arithmean    ( [ --> n/d )
 
  [ 5 makevector  
 
    say "Internal representation of a randomly generated vector" cr
    say "of five rational numbers. They are distributed between" cr
    say "-100.00 and +100.00 and are multiples of 0.01."
    cr cr dup echo cr cr
    say "Shown as decimal fractions."
    cr cr dup echodecs cr cr
 
    arithmean
 
    say "Arithmetic mean of vector as a decimal fraction to" cr 
    say "5 places after the point, as a rounded proper" cr
    say "fraction with the denominator not exceeding 10, and" cr
    say "finally as a vulgar fraction without rounding." cr cr
    2dup 5 point$ echo$
    say ", "
    2dup proper 10 round improper
    proper$ echo$
    say ", "
    vulgar$ echo$ cr cr
 
    say "The same, but with a vector of 9973 rational numbers," cr
    say "20 decimal places and a denominator not exceeding 100." cr cr
 
    9973 makevector arithmean
 
    2dup 20 point$ echo$
    say ", "
    2dup proper 100 round improper
    proper$ echo$
    say ", "
    vulgar$ echo$ cr ]       is demonstrate  (   -->     )