Skip to contents

Takes a vector, matrix or data.frame and replaces some values by NA.

Usage

generateNA(x, p = 0.1, seed = NULL)

Arguments

x

A vector, matrix or data.frame.

p

Proportion of missing values to add to x. In case x is a data.frame, p can also be a vector of probabilities per column or a named vector.

seed

An integer seed.

Value

x with missing values.

Examples

generateNA(1:10, p = 0.5)
#>  [1]  1  2  3 NA NA NA NA  8  9 NA
head(generateNA(iris, p = 0.2))
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1           NA         3.5          1.4         0.2  setosa
#> 2          4.9          NA          1.4         0.2    <NA>
#> 3          4.7         3.2          1.3          NA    <NA>
#> 4           NA         3.1           NA         0.2  setosa
#> 5           NA          NA          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa