I want to loop through the names of a character variable of this type:
names_list <- c("USA", "VEN", "CHE")
Then, I create the following loop:
for (i in names_list) {
set.seed(123333)
test <- predictors_no_NA %>%
filter(ISO3_baci != i)
predictions <- predict(rf150, test, predict.all=TRUE, type = "prob")
predictions <- as.data.frame(predictions[1])
predictions <- predictions %>%
select(aggregate.1) %>%
rename(predictions[i] = aggregate.1) % HERE APPEARS THE 1st PROBLEM
test_RF_[i] <- cbind(test, predictions) % HERE APPEARS THE 2nd PROBLEM
}
Note that variable "rf150" is created inside the loop without any problem (don't show the code here).
The problem arises when I want to add the string element of the loop (e.g. "USA") to my created name "predictions_[i]" or "test_RF_[i]", so that I can get a variable that is called: "predictions_USA" or "test_RF_USA" as well as "predictions_VEN" or "test_RF_VEN" and "predictions_CHE" or "test_RF_CHE"
Any clue?
Regards