Learn R Programming

NADIA (version 0.4.2)

simulate_missings: Generate MCAR missings in dataset.

Description

Function generates random missing values in given dataset according to set parameters.

Usage

simulate_missings(
  df,
  per_missings,
  per_instances_missings = NULL,
  per_variables_missings = NULL,
  variables_with_missings = NULL
)

Value

Dataset with generated missings.

Arguments

df

Data.frame or data.table where missing values will be generated

per_missings

Overall percentage of missing values generated in dataset. Must be set every time.

per_instances_missings

Percentage of instances which will have missing values.

per_variables_missings

Percentage of variables which will have missing values.

variables_with_missings

Only when `per_variables_missings` is `NULL`. Vector of column indexes where missings will be generated.

Examples

Run this code
{
  data_NA <- simulate_missings(iris, 20)

  # check
  sum(is.na(data_NA)) > 0
}

Run the code above in your browser using DataLab