I suspect this is an easy one. I have two datasets; dataset one has IDs in the first column, and there is exactly one row per ID. The second column has data (value1). The second dataset has the same IDs in column 1, but there are multiple instances of each ID. I would like to enter value1 into the corresponding rows of the second dataset, such that each ID gets the correct value1 from dataset1. So a one-to-many mapping problem.
Example datasets:
tC <- textConnection("ID Cat1 Cat2
1 AA BB
1 AA BB
2 CC DD
2 DD EE
2 DD FF
3 AA GG")
data1 <- read.table(header=TRUE, tC)
close.connection(tC)
rm(tC)
tC <- textConnection("ID Value1
1 a
2 b
3 c")
data2 <- read.table(header=TRUE, tC)
close.connection(tC)
rm(tC)
The final outcome should look like what results from:
tC <- textConnection("ID Cat1 Cat2 value1
1 AA BB a
1 AA BB a
2 CC DD b
2 DD EE b
2 DD FF b
3 AA GG c")
data3 <- read.table(header=TRUE, tC)
close.connection(tC)