Learn R Programming

missForest (version 1.6.1)

prodNA: Introduce Missing Values Completely at Random (MCAR)

Description

prodNA artificially introduces missing values by deleting entries completely at random (MCAR) up to a specified proportion.

Usage

prodNA(x, noNA = 0.1)

Value

An object of the same base type as x (data frame or matrix) with approximately noNA proportion of its entries set to NA.

Arguments

x

A data frame or matrix to which missing values will be added. Column classes are preserved; factors receive NA entries.

noNA

Proportion of entries in x to set to NA. Must be a number in \([0, 1]\). The default is 0.1 (10% missingness).

Author

tools:::Rd_package_author("missForest")

Details

Missingness is introduced independently and uniformly over all cells, i.e., Missing Completely At Random (MCAR). No structure by row/column or variable type is imposed.

For reproducibility, call set.seed before prodNA.

See Also

missForest, mixError

Examples

Run this code
data(iris)

## Introduce 5% MCAR missingness into the iris data set:
set.seed(81)
iris.mis <- prodNA(iris, noNA = 0.05)
summary(iris.mis)

## Higher missingness:
set.seed(81)
iris.mis.20 <- prodNA(iris, noNA = 0.20)
mean(is.na(as.matrix(iris.mis.20)))

Run the code above in your browser using DataLab