sample_char | R Documentation |
sample_char
draws a sample of
n
random characters from a given range of characters.
sample_char(x_char = c(letters, LETTERS), n = 1, replace = FALSE, ...)
x_char |
Population of characters to sample from.
Default: |
n |
Number of characters to draw.
Default: |
replace |
Boolean: Sample with replacement?
Default: |
... |
Other arguments.
(Use for specifying |
By default, sample_char
draws n = 1
a random alphabetic character from
x_char = c(letters, LETTERS)
.
As with sample()
, the sample size n
must not exceed
the number of available characters nchar(x_char)
,
unless replace = TRUE
(i.e., sampling with replacement).
A text string (scalar character vector).
Other sampling functions:
coin()
,
dice_2()
,
dice()
,
sample_date()
,
sample_time()
sample_char() # default
sample_char(n = 10)
sample_char(x_char = "abc", n = 10, replace = TRUE)
sample_char(x_char = c("x y", "6 9"), n = 6, replace = FALSE)
sample_char(x_char = c("x y", "6 9"), n = 20, replace = TRUE)
# Biased sampling:
sample_char(x_char = "abc", n = 20, replace = TRUE,
prob = c(3/6, 2/6, 1/6))
# Note: By default, n must not exceed nchar(x_char):
sample_char(n = 52, replace = FALSE) # works, but
# sample_char(n = 53, replace = FALSE) # would yield ERROR;
sample_char(n = 53, replace = TRUE) # works again.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.