samples_as_matrix: Random samples from the first natural numbers

Description Usage Arguments Details Value See Also

View source: R/samples_as_matrix.R

Description

Generate a matrix in which each row is a random sample from the set of the first n natural numbers.

Usage

1
samples_as_matrix(n, k = n, size = 0, replace = F)

Arguments

n

integer; defines set to sample from as \{1, …, n\}.

k

integer; number of items to draw from the set \{1, …, n\} in each sample (set), also the number of columns in output.

size

integer; number of (sample) sets in total, also the number of rows in output.

replace

boolean; indicate whether to sample with replacement (within the set).

Details

This is the author's best effort at efficiently generating a large number of samples of fixed length (k) from the set of the first n natural numbers without replacement. This implementation samples from the set of all combinations when n, k and size are favourable, otherwise it uses a straightforward call to base{sapply} and base{sample.int}.

When sampling with replacement, the implementation is a trivial call to link{sample.int} and a matrix constructor.

Value

matrix; a size by k matrix with a random sample from \{1, …, n\} in each row.

See Also

utils{combn} base{sample.int}


stephematician/miForang documentation built on July 23, 2019, 5:11 p.m.