title: Error in R gbm function when cv.folds > 0
body: <p>I am using gbm to predict binary response. 
  When I set cv.folds=0, everything works well. However when cv.folds > 1, I got error:<code>Error in object$var.levels[[i]] : subscript out of bounds</code> when the first irritation of crossvalidation finished. Someone said this could because some factor variables have missing levels in training or testing data, but I tried only use numeric variables and still get this error.</p>
  
  <pre><code>&gt; gbm.fit &lt;- gbm(model.formula,
  +                data=dataall_train,
  +                distribution = "adaboost",
  +                n.trees=10,
  +                shrinkage=0.05,
  +                interaction.depth=2,
  +                bag.fraction = 0.5,
  +                n.minobsinnode = 10,      
  +                train.fraction=0.5,
  +                cv.folds=3,
  +                verbose=T,
  +                n.cores=1)
  CV: 1 
  CV: 2 
  CV: 3 
  Error in object$var.levels[[i]] : subscript out of bounds
  </code></pre>
  
  <p>Anyone have some insights on this? Thanks!</p>
  
  <p>Answer my self: 
  Problem solved. This is because a bug in this function. The input data cannot contain variables other than the variables in the model.</p>