Reference/mavg

From Kx Wiki
Revision as of 15:25, 13 May 2016 by Oleg Finkelshteyn (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

mavg (moving average verb)

The mavg verb returns the N-item moving average of its numeric right argument, with any nulls after the first element replaced by zero. The first N 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.

N.B. Infinities (0w) are incompatible with this function.

Syntax

q)r:N mavg L

Example

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

See also


For a complete list of functions, see the kdb+ Function Reference.

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox