Description Details Author(s) References Examples
R's default sampling without replacement using
base::sample.int()
seems to require quadratic run time,
e.g., when using weights drawn from a uniform distribution. For large
sample sizes, this is too slow. This package contains several
alternative implementations.
Implementations are adapted from https://stackoverflow.com/q/15113650/946850.
Kirill Müller
Efraimidis, Pavlos S., and Paul G. Spirakis. "Weighted random sampling with a reservoir." Information Processing Letters 97, no. 5 (2006): 181-185.
Wong, Chak-Kuen, and Malcolm C. Easton. "An efficient method for weighted sampling without replacement." SIAM Journal on Computing 9, no. 1 (1980): 111-113.
1 | sample_int_rej(100, 50, 1:100)
|
[1] 58 67 57 84 77 20 14 86 95 64 94 49 98 79 74 85 87 62 97 60 75 45 69 59 40
[26] 72 24 78 91 90 89 65 71 76 51 54 88 82 52 39 15 47 27 42 96 99 13 92 22 63
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.