mne*_*nel 14
以下是使用Hmisc包的示例impute
library(Hmisc)
DF <- data.frame(age = c(10, 20, NA, 40), sex = c('male','female'))
# impute with mean value
DF$imputed_age <- with(DF, impute(age, mean))
# impute with random value
DF$imputed_age2 <- with(DF, impute(age, 'random'))
# impute with the media
with(DF, impute(age, median))
# impute with the minimum
with(DF, impute(age, min))
# impute with the maximum
with(DF, impute(age, max))
# and if you are sufficiently foolish
# impute with number 7
with(DF, impute(age, 7))
# impute with letter 'a'
with(DF, impute(age, 'a'))
Run Code Online (Sandbox Code Playgroud)
查看?impute有关如何实施插补的详细信息