Dataframe Joins in a loop

Hi all, I’m learning Julia and I’m stuck trying to merge several dataframes into only one using a loop.

For instances, suppose that I have 4 dataframes called A, B, C and D. They have the same column names except for the last one, named x4. And I want to merge all of them into one. So far, I’m doing this:

df1=innerjoin(A, B, on = [:x1, :x2, :x3])
df2=innerjoin(df1, C, on = [:x1, :x2, :x3])
df3=innerjoin(df2, D, on = [:x1, :x2, :x3])

How can I do this in a nice loop?

Thanks a lot!

If you don’t need a loop you can do

reduce((x, y) -> innerjoin(x, y, on =[:x1, :x2, :x3]), [A, B, C])

Why do you want a loop? Normally you can just write:

innerjoin(A, B, C, D, on = [:x1, :x2, :x3], makeunique=true)

makeunique=true is needed as I understand that you have the same column name :x4 in all data frames.


Thanks! It works well.

Thanks! It worked.