鼠标功能无法获取数据列

时间:2019-10-31 12:57:07

标签: r r-mice

当我尝试为数据估算缺失值时,鼠标功能将不会拾取具有缺失值的列。我正在尝试替换BusinessTravel中的空值,但是使用下面的代码,它不起作用

    library(mice)

    mice_mod <- mice(my_ca_dataset[, !names(my_ca_dataset) %in% 
    c('EmployeeCount', 
'JobInvolvenent', 'NumCompaniesWorked', 'TrainingTimesLastYear')], method = 'rf')

    iter imp variable
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
2 4
2 5
3 1
3 2
3 3
3 4
3 5
4 1
4 2
4 3
4 4
4 5
5 1
5 2
5 3
5 4
5 5
Warning message:
Number of logged events: 4 

mice_output <- complete(mice_mod)
my_ca_dataset$BusinessTravel <- mice_output$BusinessTravel 

sapply(my_ca_dataset, function(x) sum(is.na(x)))


Age Attrition BusinessTravel DailyRate 
0 0 31 0 
Department EmployeeCount EnvironmentSatisfaction Gender 
0 36 0 0 
HourlyRate JobInvolvement JobLevel MonthlyRate 
0 0 0 0 
NumCompaniesWorked Over18 StandardHours StockOptionLevel 
45 0 0 0 
TotalWorkingYears TrainingTimesLastYear YearsAtCompany YearsWithCurrManager 
0 0 0 0

我们需要它的工作方式是

 iter imp variable
1 1 BusinessTravel
1 2 BusinessTravel
1 3 BusinessTravel
1 4 BusinessTravel
1 5 BusinessTravel
2 1 BusinessTravel
2 2 BusinessTravel
2 3 BusinessTravel
2 4 BusinessTravel
2 5 BusinessTravel
3 1 BusinessTravel
3 2 BusinessTravel
3 3 BusinessTravel
3 4 BusinessTravel
3 5 BusinessTravel
4 1 BusinessTravel
4 2 BusinessTravel
4 3 BusinessTravel
4 4 BusinessTravel
4 5 BusinessTravel
5 1 BusinessTravel
5 2 BusinessTravel
5 3 BusinessTravel
5 4 BusinessTravel
5 5 BusinessTravel

没有显示任何错误,希望这里有人可以提供帮助

下面是数据的简要子集 A brief subset of the data is below

1 个答案:

答案 0 :(得分:0)

这些列是作为字符而不是因素存储的,并且不允许鼠标正常工作