I have the following tables:
tab_1, tab_2 tab_3, tab_4, tab_5 ... tab_20
I want to generate a bar graph where the 20 tables enter.
I use the following code:
matri1<-matrix(1:20, nrow = 10)
layout(matri1)
# Aquí realizo el bucle para asignar las tablas.
for (i in 1:20){
barplot(tab_[i])
}
But obviously, I get an error.
I don't know how to put the syntax inside the parentheses. For the 20 graphs to be generated.
Thanks in advance
When you have a set of numbered similar objects, it is good practice to handle these directly from a list and not individually. In your case where you already have the individual objects you can:
1. Pass them to a list and iterate through the elements of it
2. Get the object from the name
Here we build the name of the object
paste0("tab_", i)
from which we will later obtain a copy usingget()
, that is the main problem, the fact that we are generating a new copy, I recommend that you aim for option 1.