prodNA: Introduce Missing Values Completely at Random (MCAR)

View source: R/prodNA.R

prodNAR Documentation

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)

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).

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.

Value

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

Author(s)

Daniel J. Stekhoven [aut, cre]

See Also

missForest, mixError

Examples

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)))

missForest documentation built on Nov. 5, 2025, 6 p.m.