equalDistribution: Create a random sequence of equally distributed values

Description Usage Arguments Value Examples

Description

Create a random sequence of equally distributed values

Usage

1
equalDistribution(x, length.out = length(x), do.stop = TRUE)

Arguments

x

Vector of values to be chosen from

length.out

Length of the output vector to be created

do.stop

If TRUE (default) an error is thrown if length.out is not a multiple of the length of x. Otherwise no error is thrown.

Value

Vector of length.out values all of which are elements of x. If length.out is a multiple of the lenght of x the values are equally distributed. Otherwise (and if do.stop is FALSE so that no error is thrown) the frequencies of the values differ by one at most.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
y1 <- equalDistribution(x = LETTERS[1:2], 10)

# Check the distribution with table
table(y1)

# Do all values occur with the same frequency?
all(diff(table(y1)) == 0)

y2 <- equalDistribution(x = LETTERS[1:3], length.out = 11, do.stop = FALSE)

# Do the frequencies differ by one at most?
all(diff(table(y2)) <= 1)

hsonne/blockrand2 documentation built on May 17, 2019, 6:16 p.m.