Hi,
I am importing different dataframes from two different excel groups, and I would like to put them all together in different dataframes using loops. The problem is that I don't know how to call the dataframes bases already inside the loop.
files = c("men.xlsx", "women.xlsx")
names = c("men", "women")
names_def = c("men_def", "women_def")
years = as.character(2010:2020)
men_def= list()
women_def= list()
for (j in seq_along(years)) {
for (i in seq_along(files)) {
assign(names[i], read_excel(path = files[i], sheet=years[j]))
assign(names_def[i], rbind(names[[i]], names_def[[i]]))
}
}
The objective is that at the end of the loop you have two dataframes with all the information of all the years, but when using rbind in this way it does not replace by the name of the dataframe as I would like. But the final result is a 2x1 vector where, men_def="men", "men_def", and women_def="women", "women_def".
In other software I would use something like:
foreach i in $list {
append using`i'
}
Thanks!