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

R is not a simple programming language, and it does better on reading excel files than python

R is not a simple programming language, and it does better on reading excel files than python . tried to read excel files to python and R. i...