make_random | R Documentation |
Adds new column with random numbers. The function is built to be able to use it in piping.
make_random(data, colname = "random", seed = -1, init_seed = FALSE)
data |
[ |
colname |
[ |
seed |
[ |
init_seed |
[ |
To make reproducible random numbers the seed can be initialized with a
specific value. The first time the seed is used, set init_seed = TRUE
.
Thereafter, use init_seed = FALSE
if more random numbers are generated
in the session to avoid overlapping random numbers.
data.frame
with a new column with random numbers.
Petter Hopp Petter.Hopp@vetinst.no
## Not run:
# Add column with random variables
x <- as.data.frame(c(1:10))
seed <- 12345
# Initialize with seed first time used
x <- make_random(x, seed = seed, init_seed = TRUE)
# Do not initialize the seed thereafter to avoid overlapping
x <- make_random(x, seed = seed, init_seed = FALSE)
# If you initialize again you get overlapping seeds
x <- make_random(x, seed = seed, init_seed = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.