I have 2 types (say a and b) of dataframes in my R environment, each with 20 years. I am trying to write a loop in R such that I can merge the 1st dataframe in type a with 1st dataframe in type b by a particular variable.
I have a1,a2,...,a20 and b1,b2,...,b20 in my environment and the common variable by which I am trying to merge is ID. I have tried with the code below, but I am guessing the issue is inside the merge function where I am defining the x and y.
for (i in 1:20) {
assign(paste0("ab", i), merge(x="a"&i, y="b"&i, by.x = 'ID', by.y='ID', all.x=TRUE))
}
I want to have 20 new dataframes (called ab1, ab2,..., ab20) with the information from type a and b together. Any help will be greatly appreciated and please do point it to me in case there exists a same question.