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


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

mean <- SMA$new(c(1, 2, 3, 4, 5), window = 3)
mean$value
#> [1] 4
#> [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))