Creating a loop for different random forest training algorithms
<p>Im trying to write a for loop to create various random forest models. I've stored the variables I would like to use in the different models in a list called list:</p>

<pre><code> list &lt;- c("EXPG1 + EXPG2", "EXPG1 + EXPG2 + distance")
</code></pre>

<p>Then I try to loop over it created predictions. What I finally want to achieve is this:</p>

<pre><code>modFit1 &lt;- train(won ~ EXPG1 + EXPG2, data=training, method="rf", prox=TRUE)
modFit2 &lt;- train(won ~ EXPG1 + EXPG2 + distance, data=training, method="rf", prox=TRUE)
</code></pre>

<p>I have some issues trying to accomplish this however.</p>

<p>This doesn't work:</p>

<pre><code>modFit1 &lt;- train(won ~ list[1], data=training, method="rf", prox=TRUE)
</code></pre>

<p>And also this doesnot seem to do the trick:</p>

<pre><code>for (R in modfits) {

  modfit &lt;- paste0("won ~ ", R, ", data=training, method=\"rf\", prox=\"TRUE")
 train(modfit)

}
</code></pre>

<p>Any thoughts on what goes wrong?</p>