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:
list <- c("EXPG1 + EXPG2", "EXPG1 + EXPG2 + distance")
Then I try to loop over it created predictions. What I finally want to achieve is this:
modFit1 <- train(won ~ EXPG1 + EXPG2, data=training, method="rf", prox=TRUE)
modFit2 <- train(won ~ EXPG1 + EXPG2 + distance, data=training, method="rf", prox=TRUE)
I have some issues trying to accomplish this however.
This doesn't work:
modFit1 <- train(won ~ list[1], data=training, method="rf", prox=TRUE)
And also this doesnot seem to do the trick:
for (R in modfits) {
modfit <- paste0("won ~ ", R, ", data=training, method=\"rf\", prox=\"TRUE")
train(modfit)
}
Any thoughts on what goes wrong?