createNAvars: Make NAs available for regression

Description Usage Arguments Value Author(s) See Also Examples

Description

For numeric variables, introduces a new indicator (binary) variable for missing values and assigns a fixed, non-missing value for them in the (renamed) original variable
For factors, introduces a new level for missing values and assigns it to all missing values.

Usage

1
2
3
4
  createNAvars(data, vars=NULL, na.prop=0.1, na.label=".NA.",
    na.values = NULL, name.suffix=c(".X",".NA"), append=TRUE, ...)
  factorNA(data, na.label = ".NA.",na.prop=0,  ...)
  xNA(data, na.values = NULL, na.prop=0.1, name.suffix=c(".X",".NA"))

Arguments

data

a data.frame of quantitative variables. A vector will be converted to a one column data.frame

vars

variables (column names or indexes) to be treated. It is usually not needed to specify vars since only those variables are treated that contain missing values.

na.prop

limit for the proportion of NAs. Only those variables are treated that contain a higher proportion of missings.

na.label

for factors, label to be used for the new level of the factor

na.values

for numeric variables, value used in the .X variable for the NAs

name.suffix

suffix to be used for the new quantitative variables and the new indicator variables

append

logical: should the modified any newly created variables be returned with the unmodified variables? If TRUE, factors will be replaced by the modified version and the created variables based on continuous variables will be appended.

...

other arguments, to be passed to the function factor

Value

data.frame, containing,

If append is true, the data.frame will be the same as the input data, except that factors containing NAs will have been modified and the variables created for numeric variables containing NAs will be appended. Note that no variables will be appended for those that did not contain any NAs.

Author(s)

Werner A. Stahel

See Also

factorNA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
data(d.blast)
dd <- d.blast
dd$location[c(1,3,5)] <- NA
rr <- createNAvars(dd, na.prop=0)

xNA(c(3,NA,NA,6,5,9,1,11))

df <- data.frame(a=c(3,NA,NA,6,5,9,1,11), b=c(1,2,1,0,3,4,2,0))
( dfn <- xNA(df) )
attr(dfn, "xNA.values")

factorNA(c("a","c",NA,"a",NA), na.label="missing")

regr0 documentation built on May 2, 2019, 4:52 p.m.

Related to createNAvars in regr0...