Thanks a lot, mduvekot!
However, i receive the following error message: "Error in get(df) : invalid first argument"?
Do you have any clue what's wrong?
Thanks again! Ehsan
year <- 2015:2022
for (i in year) {
df <- assign( paste0("df", i), read_excel("data/mydata.xlsx", sheet = paste0(i), range = "A4:H187"))
assign(df, cbind(get(df)), year = i)
"Error in assign(df, cbind(get(df)), year = i) :
unused argument (year = i)"
So I basically import Excel sheets and save as a df2015, df2016, etc.
than for each df2015 etc. I want to add a new column defining the year = 2015 etc.
at the end I want to combine all df2015-2022 into one dataframe.
Thanks for the hint. This is what I did and seems to work.
year <- 2015:2022
for (i in year) {
azryr <- assign( paste0("azr", i), read_excel("data/fdz.xlsx", sheet = paste0(i), range = "A4:H187"))
assign("azr", cbind(get("azryr"), year = i))
}
however, this creates only in data file "azr" the variable year == 2022. There is also a list of data files azr2015, azr2016, etc. but without generating the variable "year"
do you know what is missing?