VIM
VIM copied to clipboard
error in hotdeck with donor condition-> Improve error message
The function hotdeck() does sometimes give an error if a donor condition is set. I have an example below, where I couldn't find the difference between applying it on "x" or "y".
library(VIM)
set.seed(112)
n <- 10
x <- data.frame(
"x" = round(rlnorm(n), 2),
"y" = round(rlnorm(n), 2),
"c1" = factor(sample(LETTERS[1:3], n, replace = TRUE)),
"d1" = factor(sample(c("R1","R2"), n, replace = TRUE)),
"o1" = round(rnorm(n, 30, 15)),
"o2" = round(rnorm(n, 5), 2))
origX <- x
x[sample(1:n, 2), 1] <- NA
x[sample(1:n, 2), 2] <- NA
x[sample(1:n, 2), 3] <- NA
x #> x
x y c1 d1 o1 o2
#1 0.73 0.39 A R2 31 3.08 #2 11.06 NA C R1 29 4.49 #3 0.49 0.84 <NA> R1 30 5.29 #4 0.17 6.50 B R2 51 3.66 #5 0.32 0.60 B R2 12 4.45 #6 0.49 NA B R2 42 5.28 #7 3.71 3.17 B R2 31 5.25 #8 NA 0.86 B R1 18 6.43 #9 1.16 0.77 <NA> R1 26 4.53 #10 NA 1.60 B R2 29 5.01
#hotdeck with donorcond on x does work. hotdeck(x, variable = "x", domain_var = "d1", donorcond = list(">2"))
#but hotdeck with donorcond on y does not? hotdeck(x, variable = "y", domain_var = "d1", donorcond = list(">2"))
In the group x[x$d1=="R1","x"] no observation is >2, so the error is correct. But the error message is not really easy to get.