Similar to standard sample
function. Safe sample function considering the special case of an integer vector with only one element.
safe_sample(x, size, replace = FALSE, prob = NULL)
A vector with the elements chosen.
a vector with the alternatives to choose.
an integer with the number of elements to select from x
.
a boolean indicating if the elements should be chosen with replacement (default: FALSE
).
a double vector with the probability associated to each element (default: NULL
).