Simulate an integer vector
sim_integer.RdSimulate a vector of random integer values. Provides the option of inserting zeros, base::NA, base::NaN, and base::Inf values or returning base::NULL or zero-length objects.
Usage
sim_integer(
x = -10:10,
length = c(1, 10),
prob_zero = 1,
n_zero = 1L,
prob_na = 0,
n_na = 1L,
prob_nan = 0,
n_nan = 1L,
prob_inf = 0,
n_inf = 1L,
prob_null = 0,
prob_zero_length = 0,
names = FALSE,
replace = TRUE
)Arguments
- x
(integer)
The vector to randomly sample from.- 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_zero
(Scalar numeric:
[0, 1])
The probability of inserting a0.- n_zero
(Scalar integer:
[0, Inf])
The number of0s to insert.- prob_na
(Scalar numeric:
[0, 1])
The probability of inserting anNA.- n_na
(Scalar integer:
[0, Inf])
The number ofNAs to insert.- prob_nan
(Scalar numeric:
[0, 1])
The probability of inserting aNaN.- n_nan
(Scalar integer:
[0, Inf])
The number ofNaNs to insert.- prob_inf
(Scalar numeric:
[0, 1])
The probability of inserting anInf.- n_inf
(Scalar integer:
[0, Inf])
The number ofInfs 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, ...- replace
(Scalar logical:
c(TRUE, FALSE))
Whether or not elements fromxcan be repeated in the result.TRUE(default) samples with replacement.
See also
Other simulate:
insert_value(),
rand_chars(),
sim_character(),
sim_data.frame(),
sim_date(),
sim_datetime(),
sim_double(),
sim_factor(),
sim_logical()
Examples
#----------------------------------------------------------------------------
# sim_integer() examples
#----------------------------------------------------------------------------
library(bkcheck)
sim_integer()
#> [1] 4 0 3
sim_integer(prob_na = 1)
#> [1] NA -1 0
sim_integer(prob_na = 1, prob_nan = 1, prob_inf = 1)
#> [1] NA NaN Inf 0 2 -10
sim_integer(prob_null = 1)
#> NULL
sim_integer(prob_zero_length = 1)
#> integer(0)
sim_integer(names = TRUE)
#> name_1 name_2 name_3 name_4 name_5 name_6 name_7 name_8 name_9 name_10
#> -2 8 -8 -6 10 -5 0 -9 -10 8