SMA: Create a streamer for calculating the simple moving average

Description Format Methods Examples

Description

SMA creates a streaming algorithm that can be used to keep track of the mean of the previous k datapoints

Format

An R6Class generator object

Methods

Public methods


Method new()

Creates a new SMA streamer object.

Usage
SMA$new(x = NULL, window = NULL)
Arguments
x

values to be used during initialisation (optional)

window

size of the window

Returns

The new SMA (invisibly)

Examples
mean <- SMA$new(window = 5)


Method update()

Resets the SMA streamer object.

Usage
SMA$update(x)
Arguments
x

values to be added to the stream

Returns

The updated SMA (invisibly)

Examples
mean <- SMA$new(c(1, 2, 3), window = 3)
mean$update(c(4, 5))


Method clone()

The objects of this class are cloneable with this method.

Usage
SMA$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
mean <- SMA$new(c(1, 2, 3, 4, 5), window = 3)
mean$value
#> [1] 4


## ------------------------------------------------
## Method `SMA$new`
## ------------------------------------------------

mean <- SMA$new(window = 5)


## ------------------------------------------------
## Method `SMA$update`
## ------------------------------------------------

mean <- SMA$new(c(1, 2, 3), window = 3)
mean$update(c(4, 5))

THargreaves/online-oceanarium documentation built on Jan. 13, 2022, 10:39 p.m.