dsample: Discrete choice sampling

Description Usage Arguments Value Examples

View source: R/utils.R

Description

A modified sampling function based on base::sample. It always assume that that x argument contains discrete values. For example, if a number 8 is given, it will assume that 8 is the only choice it has and not assume that the choices are number 1 to 8, like base::sample does. This feature makes it safe when the choices are discrete numbers and use in a programmatic way.

Usage

1
dsample(x, size = 1, replace = FALSE, prob = NULL)

Arguments

x

a vector that contains value(s) that represents a choiceset.

size

a non-negative integer giving the number of items to choose.

replace

should sampling be with replacement?

prob

a vector of probability weights for obtaining the elements of the vector being sampled.

Value

returns a vector of the same type as x with length of size.

Examples

1
2
3
dsample(7, 10, replace = TRUE) # equivalent to rep(7, 10)
dsample(7, 1)
dsample(7) # which is equivalent to the above

dymium-org/dymiumCore documentation built on July 18, 2021, 5:10 p.m.