sample.weighted | R Documentation |
Implementation of the Weighted random sampling with a reservoir (without replacement) (Efraimidis & Spirakis, 2006) algorithm.
sample.weighted(x, size, prob)
x |
a vector of one or more elements from which to choose. |
size |
a non-negative integer giving the number of items to choose. |
prob |
a vector of weights for obtaining the elements of the vector being sampled. |
A vector of length size
with elements drawn from x
Efraimidis & Spirakis (2006). Weighted random sampling with a reservoir
N = 1000
x = seq_len(N)
prob = c(rep(0.1, N/2), rep(1, N/2))
x_sample = sample.weighted(x=x, prob=prob, size=N/2)
hist(x_sample)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.