Error in Model with caret Package I am running the following code with data traing with targetBuy as response 
variable

# load the library
library(caret)
library(klaR)

# define training control
train_control &lt;- trainControl(method = "repeatedcv", number = 10, repeats = 3)
model &lt;- train(TargetBuy ~ ., data = traing, trControl = train_control, method = "nb")
print(model)


Getting the following error


  Error in train(TargetBuy ~ ., data = traing, trControl =
  train_control,  :     unused arguments (data = traing, trControl =
  train_control, method = "nb")
Please read carefully caret::train since S3 method for class formula is slightly different than default S3 method for caret::train (and takes different arguments)

This should do the work:

model &lt;- caret::train(y = traing$TargetBuy, x = traing[, colnames(traing) != 'TargetBuy'], trControl = train_control, method = "nb")


You can also use model.matrix, but then you need to remember that it removes missing values. See this post for solution:

model &lt;- caret::train(y = factor(traing$TargetBuy), x = model.matrix(TargetBuy ~ ., data = traing), trControl = train_control, method = "nb")