# introduce missing values
# in Petal.Length of iris dataset
set.seed(13579)
pos <- sample(x = 1:nrow(iris), size = 15,
replace = FALSE)
iris.rec <- iris[pos, ] # recipient data.frame with missing values
iris.rec[, "Petal.Length"] <- NA
iris.don <- iris[-pos, ] # donor data.frame ALL observed
# find the closest donors using NND hot deck;
# distances are computed on "Petal.Width"
# donors only of the same Specie
out.NND <- NND.hotdeck(data.rec=iris.rec, data.don=iris.don,
match.vars=c("Petal.Width"),
don.class="Species")
# impute missing
iris.rec.imp <- create.imputed(data.rec=iris.rec, data.don=iris.don,
mtc.ids=out.NND$mtc.ids)
summary(iris.rec.imp$Petal.Length)
Run the code above in your browser using DataLab