My R knowledge is very limited. For a paper I'm working on, I need to combine two data sets (openness of trade and co2 output) to do a regression analysis.
These are the data sets https://ourworldindata.org/grapher/trade-openness https://github.com/owid/co2-data, which I converted to .xlsx (https://1drv.ms/x/s!ArVyXA5cSMj2h6pUWPU9ns2UkJW-ww?e=8jne7b & https://1drv.ms/x/s!ArVyXA5cSMj2h6pSE9lx6DNxhVOang?e=TqQwbI).
I imported both data sets to R (had to use the "import datasheet" tool in RStudios, because I was getting this error when trying to import them via comand), renamed them and made sure all matching columns were named the same:
open <- trade_openness co2 <- owid_co2_data_1 rm(trade_openness) rm(owid_co2_data_1)
names(open)[1] <- "country"
names(open)[2] <- "iso_code"
names(open)[3] <- "year"
names(open)[4] <- "openness"
Now I wanted to merge both datasets to have the trade openness data next to the co2 data. For example
# | country | iso_code | year | openness | co2 | co2_growth_prct | ...
After watching some youtube guides on merging data frames I tried this function:
merge(open, co2, by = "country", "year", all.x = TRUE)
This did something, but not what I was hoping for. Also I noticed it left the existing data frames untouched, so I'm guessing I need to add a comand to create a new, merged data frame?
I feel like this should be relatively simply, but I don't know how do this. Could someone please help me out with this?
Best regards!