smpl {xpectr} | R Documentation |
Random sampling
Description
Samples a vector
, factor
or data.frame
. Useful to reduce size of testthat expect_*
tests.
Not intended for other purposes.
Wraps sample.int()
. data.frame
s are sampled row-wise.
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.
Usage
smpl(data, n, keep_order = TRUE, seed = 42)
Arguments
data |
|
n |
Number of elements/rows to sample. N.B. No replacement is used, why |
keep_order |
Whether to keep the order of the elements. (Logical) |
seed |
The |
Value
When `data`
has <=`n`
elements, `data`
is returned.
Otherwise, `data`
is sampled and returned.
Author(s)
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Examples
# 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)