Learn R Programming

specmine (version 4.0.0)

impute_nas_knn: Impute missing values with kNN

Description

Replace missing values using k-nearest neighbors imputation.

Usage

impute_nas_knn(dataset, k = 10, ...)

Value

A dataset object with the same structure as the input, where missing values in `dataset$data` have been imputed using the k-nearest neighbors method implemented in `impute::impute.knn()`. The returned object preserves the remaining dataset components unchanged.

Arguments

dataset

A dataset object to modify.

k

Number of neighbors to use in the imputation procedure.

...

Additional arguments passed to `impute::impute.knn()`.

Examples

Run this code
# \donttest{
data <- matrix(
  c(1,  2, NA, 4,
    2,  3,  4, 5,
    3, NA,  5, 6,
    4,  5,  6, 7),
  nrow = 4,
  byrow = TRUE,
  dimnames = list(c("x1", "x2", "x3", "x4"), c("s1", "s2", "s3", "s4"))
)
dataset <- list(data = data)
impute_nas_knn(dataset, k = 2)
# }

Run the code above in your browser using DataLab