R中的估算

Meh*_*ani 5 r imputation

我是R编程语言的新手.我只是想知道有没有办法在我们的数据集中只包含一列的空值.因为我看到的所有插补命令和库都会归因于整个数据集的空值.

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有关如何实施插补的详细信息

  • 另外*如果*你已经阅读了'impute`的帮助文件(正如我建议的那样!),你会发现你可以通过一个函数进行估算. (3认同)