Learn R Programming

simFrame (version 0.1.2)

setNA: Set missing values

Description

Generic function for inserting missing values into data.

Usage

setNA(x, control, ...)

## S3 method for class 'data.frame,NAControl': setNA(x, control, i)

Arguments

x
the data in which missing values should be inserted.
control
a control object inheriting from the virtual class "VirtualNAControl" or a character string specifying such a control class (the default being "NAControl").
i
an integer giving the element or row of the slot NArate of control to be used as missing value rate(s).
...
if control is a character string or missing, the slots of the control object may be supplied as additional arguments.

Value

  • A data.frame containing the data with missing values. For every target variable, a logical variable indicating the observations set to NA is added to the data.frame. The names of these columns start with a dot, followed by the name of the corresponding target variable (e.g., if missing values are generated in column "foo", a column ".foo" is added).

Details

In order to extend the framework by a user-defined control class "MyNAControl" (which must extend "VirtualNAControl"), a method setNA(x, control, i) with signature 'data.frame, MyNAControl' needs to be implemented.

See Also

NAControl, VirtualNAControl

Examples

Run this code
data(eusilc)
sam <- draw(eusilc[, c("id", "age", "eqIncome")], size = 25)

## missing completely at random
setNA(sam, target = "eqIncome", NArate = 0.2)

## missing at random
setNA(sam, target = "eqIncome", NArate = 0.2, aux = "age")

## missing not at random
setNA(sam, target = "eqIncome", NArate = 0.2, aux = "eqIncome")

Run the code above in your browser using DataLab