title: Subscript out of bound error in predict function of randomforest
body: <p>I am using random forest for prediction and in the <code>predict(fit, test_feature)</code> line, I get the following error. Can someone help me to overcome this. I did the same steps with another dataset and had no error. but I get error here.</p>
  
  <pre><code>Error: Error in x[, vname, drop = FALSE] : subscript out of bounds
  
  training_index &lt;- createDataPartition(shufflled[,487], p = 0.8, times = 1)
  training_index &lt;- unlist(training_index)
  
  train_set &lt;- shufflled[training_index,]
  test_set &lt;- shufflled[-training_index,]
  
  accuracies&lt;- c()
  k=10
  n= floor(nrow(train_set)/k)
  
  for(i in 1:k){
    sub1&lt;- ((i-1)*n+1)
    sub2&lt;- (i*n)
    subset&lt;- sub1:sub2
    train&lt;- train_set[-subset, ]
    test&lt;- train_set[subset, ]
    test_feature&lt;- test[ ,-487]
  
    True_Label&lt;- as.factor(test[ ,487])
    fit&lt;- randomForest(x= train[ ,-487], y= as.factor(train[ ,487]))
  
    prediction&lt;- predict(fit, test_feature)  #The error line
    correctlabel&lt;- prediction == True_Label
    t&lt;- table(prediction, True_Label)
  }
  </code></pre>