Description Format Methods Examples
ReservoirSampler
creates a streaming algorithm that can
be used to obtain a random sample from a population that is too large to
fit in memory. The samples can be made reproducible can be using
'set.seed(...)' before initialising the streamer.
Implementation is based on doi:10.1145/198429.198435.
An R6Class
generator object
new()
Creates a new ReservoirSampler
streamer object.
ReservoirSampler$new(k)
k
the desired sample size
The new ReservoirSampler
(invisibly)
update()
Update the ReservoirSampler
streamer object.
ReservoirSampler$update(x)
x
values to be added to the stream
The updated ReservoirSampler
(invisibly)
clone()
The objects of this class are cloneable with this method.
ReservoirSampler$clone(deep = FALSE)
deep
Whether to make a deep clone.
1 2 3 4 5 6 | sampler <- ReservoirSampler$new(k = 10)
for (i in 1:100) {
sampler$update(i)
}
length(sampler$value) # random sample from 1:100 of size 10
#> [1] 10
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.