Description Format Methods Examples
SMA
creates a streaming algorithm that can be used to
keep track of the mean of the previous k datapoints
An R6Class
generator object
new()
Creates a new SMA
streamer object.
SMA$new(x = NULL, window = NULL)
x
values to be used during initialisation (optional)
window
size of the window
The new SMA
(invisibly)
mean <- SMA$new(window = 5)
update()
Resets the SMA
streamer object.
SMA$update(x)
x
values to be added to the stream
The updated SMA
(invisibly)
mean <- SMA$new(c(1, 2, 3), window = 3) mean$update(c(4, 5))
clone()
The objects of this class are cloneable with this method.
SMA$clone(deep = FALSE)
deep
Whether to make a deep clone.
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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.