Simulate a double-precision vector
sim_double.RdSimulate a vector of random double-precision values (base::numeric()).
Provides the option of inserting zeros, base::NA, base::NaN, and base::Inf values or returning base::NULL or zero-length objects.
Arguments
- x
(Double-precision vector)
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.
Details
The arguments list contains many possible conditions.
Combining more than one set of conditions may not necessarily result in the specified behavior.
For example, sim_double(prob_null=0.9, prob_zero_length=0.9) does not result in NULL and zero-length outcomes each with probability 0.9.
See also
Other simulate:
insert_value(),
rand_chars(),
sim_character(),
sim_data.frame(),
sim_date(),
sim_datetime(),
sim_factor(),
sim_integer(),
sim_logical()
Examples
#----------------------------------------------------------------------------
# sim_double() examples
#----------------------------------------------------------------------------
library(bkcheck)
sim_double()
#> [1] 9.388087 -3.395493 3.412463 9.388087 -6.148026 -4.091817 0.000000
sim_double(prob_na = 1)
#> [1] 9.699435 5.909007 4.727261 7.220465 2.829648 -2.716598 4.727261
#> [8] NA 0.000000 4.727261
sim_double(length = 4, prob_na = 1, prob_nan = 1, prob_inf = 1)
#> [1] Inf NaN NA 8.923015
sim_double(prob_null = 1)
#> NULL
sim_double(prob_zero_length = 1)
#> numeric(0)
sim_double(names = TRUE)
#> name_1 name_2 name_3
#> -8.162032 0.000000 -3.119739