title: r random forest error - type of predictors in new data do not match
body: <p>I am trying to use quantile regression forest function in R (<a href="http://cran.r-project.org/web/packages/quantregForest/quantregForest.pdf">quantregForest</a>) which is built on Random Forest package. I am getting a type mismatch error that I can't quite figure why.</p>
  
  <p>I train the model by using</p>
  
  <pre><code>qrf &lt;- quantregForest(x = xtrain, y = ytrain)
  </code></pre>
  
  <p>which works without a problem, but when I try to test with new data like</p>
  
  <pre><code>quant.newdata &lt;- predict(qrf, newdata= xtest)
  </code></pre>
  
  <p>it gives the following error:</p>
  
  <pre><code>Error in predict.quantregForest(qrf, newdata = xtest) : 
  Type of predictors in new data do not match types of the training data.
  </code></pre>
  
  <p>My training and testing data are coming from separate files (hence separate data frames) but having the same format. I have checked the classes of the predictors with</p>
  
  <pre><code>sapply(xtrain, class)
  sapply(xtest, class)
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>&gt; sapply(xtrain, class)
  pred1     pred2     pred3     pred4     pred5     pred6     pred7     pred8 
  "factor" "integer" "integer" "integer"  "factor"  "factor" "integer"  "factor" 
  pred9    pred10    pred11    pred12 
  "factor"  "factor"  "factor"  "factor" 
  
  
  &gt; sapply(xtest, class)
  pred1     pred2     pred3     pred4     pred5     pred6     pred7     pred8 
  "factor" "integer" "integer" "integer"  "factor"  "factor" "integer"  "factor" 
  pred9    pred10    pred11    pred12 
  "factor"  "factor"  "factor"  "factor" 
  </code></pre>
  
  <p>They are exactly the same. I also checked for the "NA" values. Neither xtrain nor xtest has a NA value in it. Am I missing something trivial here?</p>
  
  <p>Update I: running the prediction on the training data still gives the same error</p>
  
  <pre><code>&gt; quant.newdata &lt;- predict(qrf, newdata = xtrain)
  Error in predict.quantregForest(qrf, newdata = xtrain) : 
  names of predictor variables do not match
  </code></pre>
  
  <p>Update II: I combined my training and test sets so that rows from 1 to 101 are the training data and the rest is the testing. I modified the example provided in (<a href="http://cran.r-project.org/web/packages/quantregForest/quantregForest.pdf">quantregForest</a>) as:</p>
  
  <pre><code>data &lt;-  read.table("toy.txt", header = T)
  n &lt;- nrow(data)
  indextrain &lt;- 1:101
  xtrain &lt;- data[indextrain, 3:14]
  xtest &lt;- data[-indextrain, 3:14]
  ytrain &lt;- data[indextrain, 15]
  ytest &lt;- data[-indextrain, 15]
  
  qrf &lt;- quantregForest(x=xtrain, y=ytrain)
  quant.newdata &lt;- predict(qrf, newdata= xtest)
  </code></pre>
  
  <p>And it works! I'd appreciate if any one could explain why it works this way and not with the other way?</p>