Actually, the need being merging both data sets to have columns form each, the size difference is not a problem as we are not juxtaposing columns, we are merging them based on the values of the year and location fields from each data sets. So the merging will have a multivariable merging key (or we can simply concatenate them into one variable to have a simpler key). In all cases we can have 3 different cases:
- key=(year, location) in both D1 and D2
- key=(year, location) in D1 but not in D2
- key=(year, location) in D2 but not in D1
I presume that the visualisation needs the columns from both D1 and D2 (the first bullet point): an inner join of the data sets is then needed.
to perform it in R, we can use the data.table package which have a very simple syntax.
library(data.table)
# Extract the data in a data.table format
# can be replaced by reading from a file using fread or any other command to have both data sets as data tables.
dt1 <- as.data.table(df1)
dt2 <- as.data.table(df2)
# set the merging key in each data table
setkey(dt1, "year", "location")
setkey(dt2, "year", "location")
# merge data tables
dt.result <- merge(dt1, dt2) # keep the default settings (inner join)