| inject_nas | R Documentation |
Apply random or systematic missingness to existing data according to recipe
inject_nas(tbl, recipe)
tbl |
data.frame/tibble. The already generated data to inject missingness into |
recipe |
tibble. A recipe for generating missingness positions |
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.
tbl, with missingness injected into it as laid out by recipe
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.