
This function creates missing values under the missing complete at random (MCAR) mechanism. It is for demonstration purposes only.
createNA(data, var.names = NULL, p = 0.3)
A data frame with artificial missing values
A complete data frame.
The names of variables where missing values will be generated.
The proportion of missing values in the data frame or the proportions of missing values corresponding to the variables specified in var.names
.
# Create 30% MCAR data across all variables in a dataset
withNA.df <- createNA(data = iris, p = 0.3)
# Create 30% MCAR data in a specified variable in a dataset
withNA.df <- createNA(data = iris, var.names = c("Sepal.Length"), p = 0.3)
# Create MCAR data in several specified variables in a dataset
withNA.df <- createNA(
data = iris,
var.names = c("Sepal.Length", "Petal.Width", "Species"),
p = c(0.3, 0.2, 0.1)
)
Run the code above in your browser using DataLab