Error in na.fail.default: missing values in object - but no missing values

随声附和 提交于 2019-11-28 11:58:00

tl;dr you have to use na.exclude() (or whatever) on the whole data frame at once, so that the remaining observations stay matched up across variables ...

set.seed(101)
tot_nochc=runif(10,1,15)
cor_partner=factor(c(1,1,0,1,0,0,0,0,1,0))
age=runif(10,18,75)
agecu=age^3
day=factor(c(1,2,2,3,3,NA,NA,4,4,4))
## use data.frame() -- *DON'T* cbind() first
dt=data.frame(tot_nochc,cor_partner,agecu,day)
## DON'T attach(dt) ...

Now try:

library(nlme)
corpart.lme.1=lme(tot_nochc~cor_partner+agecu+cor_partner *agecu, 
              random = ~cor_partner+agecu+cor_partner *agecu |day, 
              data=dt,
              na.action=na.exclude)

We get convergence errors and warnings, but I think that's now because we're using a tiny made-up data set without enough information in it and not because of any inherent problem with the code.

kurapati

randomForest package has a na.roughfix function that "imputes Missing Values by median/mode"

You can use it as follows

fit_rf<-randomForest(store~.,
        data=store_train,
        importance=TRUE,
        prOximity=TRUE,
        na.action=na.roughfix)
Aakash Choudhary

if your data contain Na or missing values you can use this it will pass the data exactly the same as it is in datasets.

rf<-randomForest(target~.,data=train, na.action = na.roughfix)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!