I have two datasets from the Global Energy Monitor and want to merge them using RStudio. Both datasets show the “TrackerID” of different power plants. Dataset1 lists every TrackerID 1, 2, 3, ..., i. In Dataset2, some TrackerIDs are missing, while others are used several times. Therefore, one TrackerID in Dataset2 can have different values of the variable "signatory".
I would like to merge the datasets. Each observation from dataset 1, for which there are several observations in dataset 2, is to be duplicated so that each observation from dataset 2 has its own row.
This is a sample dataset to better understand my question. The original Dataset includes way more variables and observations.
Dataset1 <- data.frame(TrackerID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
Dataset2 <- data.frame(TrackerID = c(1, 3, 3, 6, 7, 7, 7, 10),
Signatory= c(1, 1, 0, 0, 1, 0, 1, 1))
This is what the Dataset created should look like:
Dataset.wished <- data.frame(TrackerID = c(1, 2, 3, 3_1, 4, 5, 6, 7, 7_1, 7_2, 8, 9, 10),
Signatory = c(1, "NA", 1, 0, "NA", "NA", 0, 1, 0, 1, "NA", "NA", 1))