I have multiple files in a list and I want to merge them based on Year
column, so that my new file
looks like Merged_file
. I could use merge(file1, file2, by="Year")
if I had 2 files, but I don't know how to do that for multiple files in a list.
I also tried this newlist <- lapply(files, function(t)do.call(rbind.fill, t))
but its not what I want.
file1 file2 Merged_file
Year Value1 Year Value2 Year Value1 Value2
2001 1 2000 0.5 2001 1 0.3
2001 2 2000 0.6 2001 2 0.3
2002 2 2001 0.3 2002 2 0.5
2002 3 2001 0.3 2002 3 0.6
2003 3 2002 0.5 2003 3 0.6
2003 4 2002 0.6 2003 4 0.6
2003 0.6
2003 0.6