Skip to contents

This function inserts NA's to the provided matrix according to the MCAR (Missing Completely At Random) pattern.

Usage

insert_MCAR(dat, ratio = 0, thresh = 0.2)

Arguments

dat

a matrix or data.frame of data to be filled with some NA's.

ratio

a number from 0 to 1 denoting the ratio of data to be exchanged into NA's

thresh

a value from 0 to 1: limit value indicating maximum ratio of missing observations in one column

Value

A matrix with NA values inserted.

Examples

set.seed(1)
m <- as.data.frame(matrix(rnorm(50), ncol = 10))
insert_MCAR(m, ratio = 0.1)
#>           V1         V2         V3          V4          V5          V6
#> 1 -0.6264538 -0.8204684  1.5117812 -0.04493361  0.91897737 -0.05612874
#> 2         NA         NA  0.3898432 -0.01619026  0.78213630          NA
#> 3 -0.8356286  0.7383247 -0.6212406          NA  0.07456498 -1.47075238
#> 4  1.5952808  0.5757814 -2.2146999  0.82122120 -1.98935170 -0.47815006
#> 5  0.3295078 -0.3053884  1.1249309  0.59390132  0.61982575  0.41794156
#>            V7         V8         V9        V10
#> 1  1.35867955 -0.4149946 -0.1645236 -0.7074952
#> 2 -0.10278773 -0.3942900 -0.2533617  0.3645820
#> 3  0.38767161 -0.0593134  0.6969634  0.7685329
#> 4 -0.05380504  1.1000254         NA -0.1123462
#> 5 -1.37705956  0.7631757 -0.6887557  0.8811077