impute: Replace Missing Values

Description Usage Arguments Value Author(s) Examples

View source: R/impute.R

Description

Replaces missing values of a matrix or dataframe with the medians (what="median") or means (what="mean") of the respective columns.

Usage

1
impute(x, what = c("median", "mean"))

Arguments

x

A matrix or dataframe.

what

What to impute.

Value

A matrix or dataframe.

Author(s)

Friedrich Leisch

Examples

1
2
3
4
x<- matrix(1:10, ncol=2)
x[c(1,3,7)] <- NA
print(x)
print(impute(x))

Example output

     [,1] [,2]
[1,]   NA    6
[2,]    2   NA
[3,]   NA    8
[4,]    4    9
[5,]    5   10
     [,1] [,2]
[1,]    4  6.0
[2,]    2  8.5
[3,]    4  8.0
[4,]    4  9.0
[5,]    5 10.0

e1071 documentation built on May 31, 2017, 4:17 a.m.