The set of function that allows to perform most common operations ion data sample.

unique_sample(sim_expr, ..., unique = TRUE, n_name = "n", n_iter = 10)

na_rand(sample_vec, na_ratio, not_null = FALSE)

levels_rand(sample_vec, levels_ratio, unique)

Arguments

sim_expr

Expression to be evaluated in order to get column sample.

...

Parameters and their values that are used in sim_expr.

unique

If TRUE the function will try to simulate unique values.

n_name

Name of the parameter providing sample length (for example 'n' for rnorm and 'size' for sample).

n_iter

Number of iteration to make to assure the returned values are unique.

sample_vec

Vector to which NA values should be injected.

na_ratio

Ratio (in terms of column length) of NA values to attach to the sample.

not_null

Information whether NA's are allowed.

levels_ratio

Ratio of unique levels in terms of whole sample length.

Details

unique_sample - takes simulation expression and assures the expression will be executed as many times as needed to return unique result sample. na_rand - attaches NA values to the sample according to provided NA's ratio. levels_rand - takes provided number of sample levels, and assures the returned sample have as many levels as requested.

Examples


unique_sample(rnorm(n, mean = my_mean), n = 10, my_mean = 2)
#>  [1] -0.9751768  1.4232448  2.3145267  1.3069100  2.5500642  1.8788824
#>  [7]  2.6350277  1.0081140  2.2643543  1.5788523
unique_sample(sample(values, size, replace = TRUE), size = 10, values = 1:10, n_name = "size")
#> Error in unique_sample(sample(values, size, replace = TRUE), size = 10,     values = 1:10, n_name = "size"): It wasn't possible to generate the unique sample. Please make sure sampling configuration is correct.

if (FALSE) {
  ## In 10 iterations it was not possible to simulate 6 unique values from the vector 1:5
  unique_sample(sample(values, size, replace = TRUE), size = 6, values = 1:5, n_name = "size")
}

na_rand(1:10, na_ratio = 0.5)
#>  [1]  1  2 NA NA NA  6  7 NA NA 10