ezoic

Tuesday, March 24, 2020

how to fix R's error Error: variables "xxx" were specified with different types from the fit

In R's predicting modeling, sometimes there is an error:

 Error: variables ‘xxx"  were specified with different types from the fit

How to fix it?

Mainly the reason for it is that in the data where we did the predicting  the data type for some variables are different from the data type for some variables from the modeling.

You can check the data types in the data where we will do the predicting.

Once I found that , there were some quotes in the data which made the data into character. Then I unquoted the data and made the data types into numerical. problem solved.

Sample script:

newData=noquote(newData)

newData$in_dream1<-as.numeric(newData$in_dream1)
newData$selected_by1<-as.numeric(newData$selected_by1)
newData$form1<-as.numeric(newData$form1)
newData$points_game1<-as.numeric(newData$points_game1)
newData$element_type1<-as.factor(newData$element_type1)

No comments:

Post a Comment

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...