inject_nas: Apply random or systematic missingness to existing data...

View source: R/create_data.R

inject_nasR Documentation

Apply random or systematic missingness to existing data according to recipe

Description

Apply random or systematic missingness to existing data according to recipe

Usage

inject_nas(tbl, recipe)

Arguments

tbl

data.frame/tibble. The already generated data to inject missingness into

recipe

tibble. A recipe for generating missingness positions

Details

Unlike in data-generation recipes, the func column in a missingness recipe must return a logical vector of length n or an n x k logical matrix, where n is the number of rows in .df and k is the number of variables listed in this row of the recipe. A vector is only allowed when only one variable is listed in the recipe row (ie k=1). TRUE in the return value indicates that position in the column being processed should be set to missing (NA), while FALSE indicates the value already there should remain unchanged.

Value

tbl, with missingness injected into it as laid out by recipe

Examples

library(tibble)
missrec <- tibble(variables = "wt", func = list(function(.df) rep(c(TRUE, FALSE), times = c(3, NROW(.df) - 3))), func_args = list(NULL))
newdat <- inject_nas(mtcars, missrec)
head(newdat)


Roche/respectables documentation built on Oct. 2, 2024, 8:57 p.m.