sample_choice: Modified version of base::sample for programming in a Monte...

Description Usage Arguments Examples

View source: R/utils.R

Description

This version of the sample function removes the feature where x is an integer of length 1 sampling via sample takes place from 1:x. This can bring unexpected behaviour as mentioned in the documentation of base::sample().

Usage

1
sample_choice(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.

Examples

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

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