Caret + RStudio: Error "Please make sure `y` is a factor or numeric value" when training I'm new to Caret and I've been trying a couple things to get the hang of things. But this error happened to me and I'm not sure why.

I've been trying to train a model with some data I got from "PimaIndiansDiabetes". These are the "x" and "y" I'm using:


  >str(pima.Datos.Train[pima.Vars.Entrada.Usadas])
  'data.frame':   615 obs. of  8 variables:
   \$ pregnant: num  6 1 8 1 3 10 2 8 4 10 ...
   \$ glucose : num  148 85 183 89 78 115 197 125 110 139 ...
   \$ pressure: num  72 66 64 66 50 0 70 96 92 80 ...
   \$ triceps : num  35 29 0 23 32 0 45 0 0 0 ...
   \$ insulin : num  0 0 0 94 88 0 543 0 0 0 ...
   \$ mass    : num  33.6 26.6 23.3 28.1 31 35.3 30.5 0 37.6 27.1 ...
   \$ pedigree: num  0.627 0.351 0.672 0.167 0.248 ...
   \$ age     : num  50 31 32 21 26 29 53 54 30 57 ...  
  
  >str(pima.Datos.Train[pima.Var.Salida.Usada])
  'data.frame':   615 obs. of  1 variable:
   \$ diabetes: Factor w/ 2 levels "neg","pos": 2 1 2 1 2 1 2 2 1 1 ...
  
  >pima.modelo &lt;- train(pima.Datos.Train[pima.Vars.Entrada.Usadas],
                        pima.Datos.Train[pima.Var.Salida.Usada],
                        method='mlp')


train returns an Error: Please make sure y is a factor or numeric value.
But as far as I know, "y" is a factor, so I'm not really sure where the Error comes from. ¿Any help with this?
Thanks in advance
Have you done any pre-processing or data manipulation before training the model?

Its hard for me to say what is the reason the error, but I have tried to do the same task and it worked whithout errors, here is my code:

library(mlbench)
library(caret)
df &lt;- PimaIndiansDiabetes

#Using x, y arguments

modelo &lt;- train(x = df[, 1:8] , y = df$diabetes, method='mlp') 

#Using formula
modelo &lt;- train(diabetes ~.,  data = df, method='mlp') 


Both approaches valid, and produce result like this:

&gt; modelo &lt;- train(x = df[, 1:8] , y = df$diabetes, method='mlp')
&gt; modelo
Multi-Layer Perceptron 

768 samples
  8 predictor
  2 classes: 'neg', 'pos' 

No pre-processing
Resampling: Bootstrapped (25 reps) 
Summary of sample sizes: 768, 768, 768, 768, 768, 768, ... 
Resampling results across tuning parameters:

  size  Accuracy   Kappa        
  1     0.6545936   0.0000000000
  3     0.6416382  -0.0008031577
  5     0.6397277   0.0002662915

Accuracy was used to select the optimal model using the largest value.
The final value used for the model was size = 1.


Please note that your results might differ a little.