Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bigsample

Sampling from large pools


Description

bigsample samples quicker from large pools than sample does.

Usage

bigsample(x, ...)
## Default S3 method:
bigsample(x, size, replace = FALSE, prob = NULL, negative = FALSE, ...)
## S3 method for class 'ff'
bigsample(x, size, replace = FALSE, prob = NULL, ...)

Arguments

x

the pool to sample from

size

the number of elements to sample

replace

TRUE to use sampling with replacement

prob

optional vector of sampling probabilities (recyled to pool length)

negative

negative

...

...

Details

For small pools sample is called.

Value

a vector of elements sampled from the pool (argument 'x')

Note

Note that bigsample and sample do not necessarily return the same sequence of elements when set.seed is set before.

Author(s)

Daniel Adler, Jens Oehlschlägel, Walter Zucchini

See Also

Examples

message("Specify pool size")
bigsample(1e8, 10)
message("Sample ff elements (same as x[bigsample(length(ff(1:100 / 10)), 10)])")
bigsample(ff(1:100 / 10), 10)
 ## Not run: 
   message("Speed factor")
     (system.time(for(i in 1:10)sample(1e8, 10))[3]/10) 
   / (system.time(for(i in 1:1000)bigsample(1e8, 10))[3]/1000)
 
## End(Not run)

ff

Memory-Efficient Storage of Large Data on Disk and Fast Access Functions

v4.0.4
GPL-2 | GPL-3 | file LICENSE
Authors
Daniel Adler [aut], Christian Gläser [aut], Oleg Nenadic [aut], Jens Oehlschlägel [aut, cre], Martijn Schuemie [aut], Walter Zucchini [aut]
Initial release
2020-10-13

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.