I have three independent data.frames
. The three data.frames
have the same number of columns and the same number of rows. Additionally They have the same column names. I' m trying to merge the three data.frames according to column names. I'm using the following code wrote to merge two data.frames and return the number of matches.
Merged_DF = sapply(names(DF1),function(n) nrow(merge(DF1, DF2, by=n)))
The problem is that while in this example there are two data.frames, in my case I have 3 data.frames. How can I modify the code to merge three data.frames instead of two? I tried to modify the string in this way simply adding the third data.frame but it does not work:
Merged_DF = sapply(names(DF1),function(n) nrow(merge(DF1, DF2, DF3, by=n)))
It returns the following error:
Error in fix.by(by.x, x) : 'by' must specify column(s) as numbers, names or logical
Ex:
DF1
G1 G2 G3 a b f b c a c d b
DF2
G1 G2 G3 A b f b c a h M b
DF3
G1 G2 G3 a b f b l a j M v
The data.frames have around 250 rows and 50 cols.