I have downloaded the sample codes from kaggle for the randomForest benchmark [URL?] and there's this part that I don't understand.
appendNAs <- function(dataset, cols) {
append_these = data.frame( is.na(dataset[, cols] ))
names(append_these) = paste(names(append_these), "NA", sep = "_")
dataset = cbind(dataset, append_these)
dataset[is.na(dataset)] = -1
return(dataset)
}
I understand that randomForest does not accept NAs and I usually just impute them with median or rfImpute. Adding extra columns as NAs indicator is new to me. I have looked at the help file for randomForest but didn't anything useful.
Would be great if someone can explain how and why the extra columns work.