I know how to generate variable and assign value to it from here: Create a variable name with "paste" in R?
But I do not need to assign value to generated variable, I need to use variable which name is generated. Here is my code:
a1 <- 1
a2 <- 2
a3 <- 3
a4 <- 4
a5 <- 5
counter <- 1
while(counter <= 5)
{
(paste0("a", counter) + 1)
counter <- counter +1
}
Question: How to modify (paste0("a", counter) + 1)
so that code above will output in console:
2
3
4
5
6