I have the following two datasets (data1 and data2) and would like to match based on the match variable across all possible cases.
data1 <- data.frame(
match = c(rep("a",7),rep("b",7),rep("c",3),rep("d",2))
)
data2 <- data.frame(
match = c(rep("a",4),rep("b",5),rep("c",2),rep("d",9)),
unit1 =
c(300,200,300,600,250,100,90,50,10,9,9.5,80,90,50,20,30,40,70,15,190)
)
in order to create a single dataset of the following format: Also of note is that these datasets are large so will need an efficient way of doing such matching.
match unit1_1 unit1_2 unit1_3 unit1_4 unit1_5 unit1_6 unit1_7 unit1_8 unit1_9
a 300 200 300 600
a 300 200 300 600
a 300 200 300 600
a 300 200 300 600
a 300 200 300 600
a 300 200 300 600
a 300 200 300 600
b 250 100 90 50 10
b 250 100 90 50 10
b 250 100 90 50 10
b 250 100 90 50 10
b 250 100 90 50 10
b 250 100 90 50 10
b 250 100 90 50 10
c 9 9.5
c 9 9.5
c 9 9.5
d 80 90 50 20 30 40 70 15 190
d 80 90 50 20 30 40 70 15 190