r_na: Replace a Proportion of Values With NA

Description Usage Arguments Value Examples

View source: R/r_na.R

Description

Replaces a proportion of values with NA. Useful for simulating missing data.

Usage

1
r_na(x, cols = -1, prob = 0.05)

Arguments

x

A data.frame or list to randomly replace elements with NAs.

cols

Numeric indices of the columns to incude (use - to exlcude as well). Default is to assign random NAs to al columns except the first column.

prob

The proportion of each column/vector elements to assign to NA.

Value

Returns a data.frame or list with random missing values.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
r_na(mtcars)
r_na(mtcars, NULL)


library(dplyr)

r_data_frame(
    n = 30,
    id,
    race,
    age,
    sex,
    hour,
    iq,
    height,
    died,
    Scoring = rnorm,
    Smoker = valid
) %>%
    r_na(prob=.4)

wakefield documentation built on Sept. 14, 2020, 1:07 a.m.