# Is it possible to run multiple sampling methods in caret package in the same training model (R)? [closed]

I'm training a random forest model to predict a categorical outcome. Is there any way I can make the model apply four methods of sampling without having to write four separate codes (one for each sampling method)?

My code is as follows:

set.seed(17)
ctrl = trainControl(method = "repeatedcv", number=10, repeats=3, sampling = "down", classProbs = TRUE, savePredictions=TRUE, summaryFunction = twoClassSummary)
grid = expand.grid(.mtry=c(1:12))
m.rf = train(fast11 ~ ., data = fast11.inp.1, method = "rf", metric = "ROC", trControl=ctrl, tuneGrid=grid)
m.rf


I wanted to use "down, up, smote, rose" in the same code, instead of writing three identical codes just replacing "down" for "up", "rose" and "smote".

## closed as off-topic by whuber♦Jan 29 '18 at 23:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – whuber
If this question can be reworded to fit the rules in the help center, please edit the question.

Just looking into this myself. Have you tried adding a vector to the trainControl?

trainControl{
sampling = c("up", "down", "rose", "smote")
}


Otherwise you can change the trainControl sampling via:

trainControl\$sampling <- "up"


And from there it should be simple enough to construct a loop.