View source: R/functions_misc.R
sampleCap | R Documentation |
A safer version of sample with additional code so that if a sample size of n is greater than length of x, n is reduced and a reordered x is returned.
sampleCap(x, size = 500)
x |
either a vector of one or more elements from which to choose, or a positive integer. See ‘Details.’ |
size |
a non-negative integer giving the number of items to choose. |
A vector of length size or original length of x if size is too larger, with elements drawn randomly from x.
x = LETTERS
#this would cause an error is normal sample
sampleCap(x, 50)
#this is equivalent to sample
sampleCap(x, 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.