Learn R Programming

hedgehog (version 0.1)

gen-element: Random Sample Generation

Description

Generators which sample from a list or produce random integer samples. Both single sample, with gen.element; and multi-sample, with gen.sample and gen.subsequence are supported; while gen.choice is used to choose from generators instead of examples.

Usage

gen.element(x, prob = NULL)

gen.int(n, prob = NULL)

gen.choice(..., prob = NULL)

gen.subsequence(x)

gen.sample(x, size, replace = FALSE, prob = NULL)

gen.sample.int(n, size, replace = FALSE, prob = NULL)

Arguments

x

a list or vector to sample an element from.

prob

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

n

the number which is the maximum integer sampled from.

...

generators to sample from

size

a non-negative integer or a generator of one, giving the number of items to choose.

replace

Should sampling be with replacement?

Value

gen.element returns an item from the list or vector; gen.int, an integer up to the value n; gen.choice, a value from one of given selected generators; gen.subsequence an ordered subsequence from the input sequence; and gen.sample a list or vector (depending on the input) of the inputs.

For gen.element and gen.choice, shrinking will move towards the first item; gen.int will shrink to 1; gen.subsequence will shrink the list towards being empty; and gen.sample will shrink towards the original list order.

Details

These generators implement shrinking.

Examples

Run this code
# NOT RUN {
gen.element(1:10)   # a number
gen.element(c(TRUE,FALSE)) # a boolean
gen.int(10) # a number up to 10
gen.choice(gen.element(1:10), gen.element(letters))
gen.choice(NaN, Inf, gen.unif(-10, 10), prob = c(1,1,10))
gen.subsequence(1:10)

# }

Run the code above in your browser using DataLab