title: Error in `[[<-.data.frame`(`*tmp*`, i, value = integer(0)) : replacement has 0 rows, data has 207
body: <p>Total beginner with R here and I know this error has been addressed before but the answers available do not solve my problem.</p>
  
  <p>I'm trying to apply a naive bayes classifier on a test dataset but with fewer variables (columns) than the training dataset used for creating the classifier. In other words, I created the classifier to predict membership of customers in certain segments based on certain variables (8 independent variables), and it worked fine on the test dataset (identical to the training data in terms of variables), but now I want to test how the model will perform if the data I have does not include all the variables from the training data (for example, if I only have the demographics of customers. So what I did is choose certain variables (columns) from the test data like this:</p>
  
  <pre><code>data.test2 &lt;- data.test[,c(1,2,5,6,8)] 
  </code></pre>
  
  <p>the test data as such includes only five independent variables out of the original 8 in the training set. I also took out the response variable (column 9)</p>
  
  <p>However I get this error:</p>
  
  <blockquote>
    <p>Error in `[[&lt;-.data.frame`(`*tmp*`, i, value = integer(0)) :<br>
      &nbsp;&nbsp;replacement has 0 rows, data has 207</p>
  </blockquote>
  
  <p>I made sure the variables names are exactly the same as in the training data. My understanding from the package is that this should not be a problem: </p>
  
  <p><em>"New Data: A dataframe with new predictors (with possibly fewer columns than the training data). Note that the column names of newdata are matched against the training data ones."</em> </p>
  
  <p>Any ideas? Thank you!</p>