How to resolve error:non numeric argument to binary operator while applying LDA using caret

r
lda
caret

#1

Hello,

I am using the below code to run lda from the caret package in R:

ldaModel <- train(df_train[,-16], df_train[,16], 
                  method='lda', 
                  trControl=Control,  
                  metric = "Accuracy",
                  preProc = c("center", "scale"))

However I am getting an error:

What does this error mean and how to remove it?r


#2

Hi @pagal_guy

Are any of your predictor variables categorical? Try converting the factor variables to numerical variables and fit the model again. See if you can reproduce the same error.

Alternatively, you can also use the formula interface without converting the factor variables to numerical.

library(caret)
ldaModel <- train(y~.-name of variable 16, data = df_train, method = “lda”, trControl = Control, metric = “Accuracy”, preProc = c(“center”, “scale”))

Hope this helps.

Thanks,
Debarati.