# load germancredit data
data(germancredit)
library(data.table)
dat = rbind(
setDT(germancredit)[, c(sample(20,3),21)],
data.table(creditability=sample(c("good","bad"),10,replace=TRUE)),
fill=TRUE)
## replace with -1
dat_repna1 = replace_na(dat, repl = -1)
## replace with median for numeric, and mode for categorical
dat_repna2 = replace_na(dat, repl = 'median')
## replace with mean for numeric, and mode for categorical
dat_repna3 = replace_na(dat, repl = 'mean')
Run the code above in your browser using DataLab