rpart
has the ability to deal with na values by imputing them from surrogate splits. By setting usesurrogate = 2
in rpart.control
, na values are dealt with. Is there a way to get the imputed version of the dataset from the rpart object?
num <- c(5, 8, 10, 12, NA)
cat1 <- factor(c("aa", "bb", NA, "cc", "cc"))
cat2 <- c("banana", "apple", "pear", "grape", NA)
some_dat <- data.frame(num = num, cat1 = cat1, cat2 = cat2)
tree_fit = rpart(num~., some_dat, method = 'anova', control = rpart.control(cp=0,maxdepth=5, usesurrogate = 2))