title: How to coerce a list object to type 'integer', Error in R
body: <p>I am newbies in using R for Data Mining and Machine Learning. While I am studying about Naive Bayes Classified, I come across this error:</p>
  
  <blockquote>
    <p>"Error in which((sapply(newdata[ind_factor], nlevels) != sapply(tables[ind_factor], : 
      (list) object cannot be coerced to type 'integer'"</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>data &lt;- read.csv(file.choose(),header = T) 
  str(data)
  set.seed(1234)
  splitData &lt;- sample(2,nrow(data),replace = T,prob = c(0.8,0.2))
  train&lt;-data[splitData == 1,]
  test &lt;- data[splitData == 2,]
  mdl &lt;- naive_bayes(admit ~ .,data = train)
  predicted &lt;- predict(mdl, train, type = 'prob')
  </code></pre>
  
  <p>When I run the final line, it throws the error message above. Can anyone help me please!
  Thanks a lot.</p>