Learn R Programming

simFrame (version 0.5.0)

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. See "NAControl" for details on the slots.

Value

  • A data.frame containing the data with missing values.

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.

References

Alfons, A., Templ, M. and Filzmoser, P. (2010) An Object-Oriented Framework for Statistical Simulation: The RPackage simFrame. Journal of Statistical Software, 37(3), 1--36. URL http://www.jstatsoft.org/v37/i03/.

See Also

"NAControl", "VirtualNAControl"

Examples

Run this code
data(eusilcP)
eusilcP$age[eusilcP$age < 0] <- 0  # this actually occurs
sam <- draw(eusilcP[, c("id", "age", "eqIncome")], size = 20)


## using control objects
# missing completely at random
mcarc <- NAControl(target = "eqIncome", NArate = 0.2)
setNA(sam, mcarc)

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

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


## supply slots of control object as arguments
# 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