Simulate a logical vector
sim_logical.RdSimulate a vector of random logical values. Provides the option of inserting base::NA or returning base::NULL or zero-length logical.
Usage
sim_logical(
prob_true = 0.5,
length = c(1, 10),
prob_na = 0,
n_na = 1L,
prob_null = 0,
prob_zero_length = 0,
names = FALSE
)Arguments
- prob_true
(Scalar numeric:
[0, 1])
The probability of samplingTRUE. The probability of samplingFALSEis1 - prob_true.- length
(integer vector of length 1 or 2)
The number of elements in the simulated vector. Iflength(length)==1L, sets the number of elements tolength. Iflength(length)==2L, randomly selects the number of elements from the interval[min, max].- prob_na
(Scalar numeric:
[0, 1])
The probability of inserting anNA.- n_na
(Scalar integer:
[0, Inf])
The number ofNAs to insert.- prob_null
(Scalar numeric:
[0, 1])
The probability of returning aNULLobject.- prob_zero_length
(Scalar numeric:
[0, 1])
The probability of returning a zero-length vector.- names
(Scalar logical:
c(TRUE, FALSE))
Whether or not the vector should have names.TRUE(default) sets names asname_1,name_2,name_3, ...
See also
Other simulate:
insert_value(),
rand_chars(),
sim_character(),
sim_data.frame(),
sim_date(),
sim_datetime(),
sim_double(),
sim_factor(),
sim_integer()
Examples
#----------------------------------------------------------------------------
# sim_logical() examples
#----------------------------------------------------------------------------
library(bkcheck)
sim_logical()
#> [1] TRUE FALSE FALSE FALSE FALSE FALSE
sim_logical(prob_na = 1)
#> [1] FALSE TRUE TRUE TRUE FALSE NA
sim_logical(prob_null = 1)
#> NULL
sim_logical(prob_zero_length = 1)
#> logical(0)
sim_logical(names = TRUE)
#> name_1
#> FALSE