allows adding NA values to a data frame, selecting the columns and the proportion of desired NAs.

insert_na(.dataset, columns, .p = 0.01, seed = 123)

Arguments

.dataset

data frame.

columns

vector that indicates the name of the columns where the NA values will be added, in the format: c("X1", "X2") for variables X1, X2.

.p

value between 0 and 1, indicating the proportion of NA values that will be added.

seed

random number seed.

Value

the original data frame, but with the NA values added in the indicated columns.

Examples

insert_na(.dataset = iris, columns = c("Sepal.Length","Petal.Length"), .p = 0.25)
#> # A tibble: 150 x 5 #> Sepal.Width Petal.Width Species Sepal.Length Petal.Length #> <dbl> <dbl> <fct> <dbl> <dbl> #> 1 3.5 0.2 setosa 5.1 NA #> 2 3 0.2 setosa NA 1.4 #> 3 3.2 0.2 setosa 4.7 1.3 #> 4 3.1 0.2 setosa NA 1.5 #> 5 3.6 0.2 setosa NA 1.4 #> 6 3.9 0.4 setosa 5.4 1.7 #> 7 3.4 0.3 setosa 4.6 1.4 #> 8 3.4 0.2 setosa NA 1.5 #> 9 2.9 0.2 setosa 4.4 1.4 #> 10 3.1 0.1 setosa 4.9 1.5 #> # … with 140 more rows