Moving averages

x mavg y     mavg[x;y]

Where

returns the x-item simple moving averages of y, with any nulls after the first item replaced by zero. The first x items of the result are the averages of the terms so far, and thereafter the result is the moving average. The result is floating point.

q)2 mavg 1 2 3 5 7 10
1 1.5 2.5 4 6 8.5
q)5 mavg 1 2 3 5 7 10
1 1.5 2 2.75 3.6 5.4
q)5 mavg 0N 2 0N 5 7 0N    / nulls after the first are replaced by 0
0n 2 2 3.5 4.666667 4.666667

mavg is a uniform function.