Skip to contents

Add a random double variable to dataset

Usage

add_var_random_dbl(
  data,
  name = "random_dbl",
  min_val = 0,
  max_val = 100,
  overwrite = TRUE,
  seed
)

Arguments

data

A dataset

name

Name of new variable (as string)

min_val

Minimum random integers

max_val

Maximum random integers

overwrite

Can new random variable overwrite an existing variable in dataset?

seed

Seed for random number generation (integer)

Value

Dataset containing new random variable

Examples

library(magrittr)
iris %>% add_var_random_dbl() %>% head()
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species random_dbl
#> 1          5.1         3.5          1.4         0.2  setosa   38.62818
#> 2          4.9         3.0          1.4         0.2  setosa   54.23828
#> 3          4.7         3.2          1.3         0.2  setosa   74.42531
#> 4          4.6         3.1          1.5         0.2  setosa   33.33324
#> 5          5.0         3.6          1.4         0.2  setosa   32.49152
#> 6          5.4         3.9          1.7         0.4  setosa   42.37430
iris %>% add_var_random_dbl(name = "random_var") %>% head()
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species random_var
#> 1          5.1         3.5          1.4         0.2  setosa  91.637595
#> 2          4.9         3.0          1.4         0.2  setosa   7.087567
#> 3          4.7         3.2          1.3         0.2  setosa  81.009608
#> 4          4.6         3.1          1.5         0.2  setosa  48.590447
#> 5          5.0         3.6          1.4         0.2  setosa  30.523473
#> 6          5.4         3.9          1.7         0.4  setosa  61.787383
iris %>% add_var_random_dbl(min_val = 1, max_val = 10) %>% head()
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species random_dbl
#> 1          5.1         3.5          1.4         0.2  setosa   3.173445
#> 2          4.9         3.0          1.4         0.2  setosa   4.697004
#> 3          4.7         3.2          1.3         0.2  setosa   8.300575
#> 4          4.6         3.1          1.5         0.2  setosa   4.412271
#> 5          5.0         3.6          1.4         0.2  setosa   5.022552
#> 6          5.4         3.9          1.7         0.4  setosa   6.134570