I have two tables which look like the following:
Table "data" Table "countries"
------------------------------ -----------------
ID Time Country Variable Value ID Country
1 2013 Austria V1 150 1 Austria
1 2014 Austria V1 170 2 Germany
1 2015 Austria V1 200 3 Spain
2 2013 Germany V1 280
2 2015 Germany V1 350
The "data" table is a panel dataset which consits of multiple countries in multiple time periods and multiple variables (even though i just included one variable in the example). The "countries" table is a full table of all countries - here three.
What I need to do is a join which fills the missing observations in the "data" table with NAs for the value for each year! After the join the "data" table should look like this:
Table "data"
------------------------------
ID Time Country Variable Value
1 2013 Austria V1 150
1 2014 Austria V1 170
1 2015 Austria V1 200
2 2013 Germany V1 280
2 2014 Germany V1 NA
2 2015 Germany V1 350
3 2013 Spain V1 NA
3 2014 Spain V1 NA
3 2015 Spain V1 NA
I think the a right join is the right direction and it also works, but it includes the NAs just once. In the above example, Spain would only be included once in the "data" table. I did a simple join like this:
joined <- right_join(data, countries, by = c("ID"))
Is there something like a "repetitive join" for panel datasets or do I need to split the dataset into time periods, join them separately and append them afterwards?
Thank you!