Variance: Create a streamer for calculating the population and sample...

Description Format Methods Examples

Description

Variance creates a streaming algorithm that can be used to calculate the population and sample variance of incoming values

Format

An R6Class generator object

Methods

Public methods


Method new()

Creates a new Variance streamer object.

Usage
Variance$new(x = NULL, sample = FALSE)
Arguments
x

values to be used during initialization (optional)

Returns

The new Variance (invisibly)

Examples
variance <- Variance$new()


Method update()

Updates the Variance with a stream of new values

Usage
Variance$update(x)
Arguments
x

a vector of values to update the Variance

sample

for choosing between the population and sample variance. If 'TRUE' the sample variance is returned. If 'FALSE' the population variance is returned.

Returns

The updated Variance (invisibly)

Examples
variance <- Variance$new(c(1,2))
variance$update(c(3,4))


Method clone()

The objects of this class are cloneable with this method.

Usage
Variance$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
19
variance <- Variance$new(c(1, 2))
variance$update(c(3, 4))
variance$value
#> [1] 1.25


## ------------------------------------------------
## Method `Variance$new`
## ------------------------------------------------

variance <- Variance$new()


## ------------------------------------------------
## Method `Variance$update`
## ------------------------------------------------

variance <- Variance$new(c(1,2))
variance$update(c(3,4))

THargreaves/onlineoceanarium documentation built on Jan. 13, 2022, 10:41 p.m.