'How do you use the variable i in a for loop, to call upon other variables in R?

Im new to R and have trouble correctly formulating my problem, but I think you understand it when you see the code.

var_1 <- 10

var_2 <- 20

var_3 <- 30

var_4 <- 40

for (i in 1:4){
  
var_i <- var_i * i 

}

This (logically) does not work, but how do I make it work?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source