title: neuralnet: requires numeric/complex matrix/vector arguments
body: <p>I used the package <code>neuralnet</code> to build a classification model in R. However, I encountered the famous error:</p>
  <pre><code>Error in cbind(1, pred) %*% weights [[num_hidden_layers + 1]]:    
  requires numeric/complex matrix/vector arguments
  </code></pre>
  <p>There are many other similar questions here, but none of them solved my problem. These are the steps I am taking:</p>
  <ol>
  <li>Using <code>model.matrix</code> to create dummy columns (ensuring no column is factor or string)</li>
  <li>Creating a manual formula by <code>paste</code> function</li>
  <li>Training <code>neuralnet</code> using the one-hot-encoded dataset of step 1 and the formula created in step 2</li>
  </ol>
  <p>Up to here, everything is fine. No error. The model converges after 5000 iterations. However, when I use either <code>compute</code> or <code>predict</code> functions to have a prediction on the test data, it gives me the above error.</p>
  <p>I am pretty sure that the columns are the same and have the same name. Also, the class is numeric for each and every attribute. I told myself that maybe the test set is not transformed well using <code>model.matrix</code>, so I used the same training set in the predict/compute function! Surprisingly, it gives a similar error for the same training set! If the data is not a numeric/complex matrix, how is it trained at first and cannot be predicted now?</p>
  <p>PS: I cannot share the data due to a privacy issue. This is the simplified code:</p>
  <pre><code>trainset = model.matrix(~., data=train_roig)
  NN_model = neuralnet(f, trainset[,-c(1:2)], hidden = c(4,2))
  # NO ERROR
  compute(NN_model, trainset[,-c(1:2)])
  # GIVES ME THE ERROR
  predict(NN_model, trainset[,-c(1:2)])
  # GIVES ME THE SAME ERROR
  </code></pre>
  <p>Double-checking column names:</p>
  <pre><code>NN_model$model.list$variables == colnames(trainset[,-c(1:2)])
  # TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
  </code></pre>
  <p>Checking structure of trainset after applying <code>model.matrix</code>:</p>
  <pre><code>str(trainset)
  # num [1:134260, 1:19] 0 0 0 0 0 0 0 0 0 ... 
  # -attr(*, &quot;dimnames&quot;) = list of 2
  # ..$ : chr [1:134260] &quot;1&quot; &quot;2&quot; &quot;3&quot; &quot;4&quot; ...
  # ..$ : chr [1:19] &quot;Y&quot; &quot;n_trips&quot; &quot;age&quot; &quot;sexM&quot; ...
  </code></pre>