samp: Safer sampler

View source: R/samp.R

sampR Documentation

Safer sampler

Description

Present since hutils v1.4.0. Same as sample, but avoiding the behaviour when length(x) == 1L.

Usage

samp(x, size = length(x), replace = size > length(x), loud = TRUE, prob = NULL)

Arguments

x

A vector.

size

A non-negative integer, the number of items to return.

replace

Should the sampling be done with replacement? Defaults to TRUE if size > length(x), with a message.

loud

If TRUE, the default, any behaviour known to be different from sample is flagged with a message.

prob

As in sample.

Examples

samp(1:5)
sample(1:5)

samp(1:5, size = 10)  # no error
tryCatch(sample(1:5, size = 10), 
         error = function(e) print(e$m))

samp(5, size = 3)
sample(5, size = 3)



hutils documentation built on April 13, 2022, 5:23 p.m.