powered by
lifecycle::badge("experimental")
Samples a vector, factor or data.frame. Useful to reduce size of testthat expect_* tests. Not intended for other purposes.
vector
factor
data.frame
expect_*
Wraps sample.int(). data.frames are sampled row-wise.
sample.int()
The seed is set within the function with sample.kind as "Rounding" for compatibility with R versions < 3.6.0. On exit, the random state is restored.
seed
sample.kind
"Rounding"
R
< 3.6.0
smpl(data, n, keep_order = TRUE, seed = 42)
When `data` has <=`n` elements, `data` is returned. Otherwise, `data` is sampled and returned.
`data`
<=`n`
vector or data.frame. (Logical)
Number of elements/rows to sample.
N.B. No replacement is used, why n > the number of elements/rows in `data` won't perform oversampling.
n >
Whether to keep the order of the elements. (Logical)
seed to use.
The seed is set with sample.kind = "Rounding" for compatibility with R versions < 3.6.0.
sample.kind = "Rounding"
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
# Attach packages library(xpectr) smpl(c(1,2,3,4,5), n = 3) smpl(data.frame("a" = c(1,2,3,4,5), "b" = c(2,3,4,5,6), stringsAsFactors = FALSE), n = 3)
Run the code above in your browser using DataLab