sample_char {ds4psy} | R Documentation |
Draw a sample of n random characters (from given characters).
Description
sample_char
draws a sample of
n
random characters from a given range of characters.
Usage
sample_char(x_char = c(letters, LETTERS), n = 1, replace = FALSE, ...)
Arguments
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 |
Details
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).
Value
A text string (scalar character vector).
See Also
Other sampling functions:
coin()
,
dice_2()
,
dice()
,
sample_date()
,
sample_time()
Examples
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.
[Package ds4psy version 1.0.0 Index]