Learn R Programming

mixgb (version 1.5.2)

createNA: Create missing values for a dataset

Description

This function creates missing values under the missing complete at random (MCAR) mechanism. It is for demonstration purposes only.

Usage

createNA(data, var.names = NULL, p = 0.3)

Value

A data frame with artificial missing values

Arguments

data

A complete data frame.

var.names

The names of variables where missing values will be generated.

p

The proportion of missing values in the data frame or the proportions of missing values corresponding to the variables specified in var.names.

Examples

Run this code
# 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