Learn R Programming

randomForest (version 4.7-1.2)

na.roughfix: Rough Imputation of Missing Values

Description

Impute Missing Values by median/mode.

Usage

na.roughfix(object, ...)

Value

A completed data matrix or data frame. For numeric variables,

NAs are replaced with column medians. For factor variables,

NAs are replaced with the most frequent levels (breaking ties at random). If object contains no NAs, it is returned unaltered.

Arguments

object

a data frame or numeric matrix.

...

further arguments special methods could require.

Author

Andy Liaw

See Also

rfImpute, randomForest.

Examples

Run this code
data(iris)
iris.na <- iris
set.seed(111)
## artificially drop some data values.
for (i in 1:4) iris.na[sample(150, sample(20, 1)), i] <- NA
iris.roughfix <- na.roughfix(iris.na)
iris.narf <- randomForest(Species ~ ., iris.na, na.action=na.roughfix)
print(iris.narf)

Run the code above in your browser using DataLab