title: Searching for best random forest parameter by for loop in r
body: <p>everyone, i am trying to searching best parameter by for loop. However, the result is really confusing me. The following code should provide same result, since the parameter "mtry" are the same.</p>
  
  <pre><code>       gender Partner   tenure Churn
  3521     Male      No 0.992313   Yes
  2525.1   Male      No 4.276666    No
  567      Male     Yes 2.708050    No
  8381   Female      No 4.202127   Yes
  6258   Female      No 0.000000   Yes
  6569     Male     Yes 2.079442    No
  27410  Female      No 1.550804   Yes
  6429   Female      No 1.791759   Yes
  412    Female     Yes 3.828641    No
  4655   Female     Yes 3.737670    No
  </code></pre>
  
  <hr>
  
  <pre><code>RFModel = randomForest(Churn ~ .,
                       data = ggg,
                       ntree = 30,
                       mtry = 2,
                       importance = TRUE,
                       replace = FALSE)
  print(RFModel$confusion)
  
      No Yes class.error
  No   4   1         0.2
  Yes  1   4         0.2
  </code></pre>
  
  <hr>
  
  <pre><code>for(i in c(2)){
     RFModel = randomForest(Churn ~ .,
                       data = Trainingds,
                       ntree = 30,
                       mtry = i,
                       importance = TRUE,
                       replace = FALSE)
     print(RFModel$confusion)
  }
  
       No Yes class.error
  No   3   2         0.4
  Yes  2   3         0.4
  </code></pre>
  
  <hr>
  
  <ol>
  <li>Code1 and code2 should provide same output.</li>
  </ol>