I have two data frames:
df1 <- data.frame(assoc = c(2, 3.4, 4.6, -2.3, -1, 0.48, -0.4),
con = c("A","B","C","D","E","F","T"))
df2 <- data.frame(pos = c("-3", "-2", "-1", "0", "1", "2", "3"),
col1 = c("A", "B", "B", "T", "T", "D", "E"),
col2 = c("B", "T", "D", "A", "E", "C","F"))
view(df1)
con assoc
A 2
B 3.4
C 4.6
D -2.3
E -1
F 0.48
T -0.4
I would like to create a function to match the data frames so that the assigned values from df1 would appear as new columns on df2. The desired output would look like this:
pos col1 con1 col2 con2
-3 A 2 B 3.4
-2 B 3.4 T -0.4
-1 B 3.4 D -2.3
0 T -0.4 A 2
1 T -0.4 E -1
2 D -2.3 C 4.6
3 E -1 F 0.48
I've tried to use:
res <- merge(df1, df2)
view(res)
Unfortunately, it worked just for one example. When I added a new column, it didn't seem to work.
Any help would be highly appreciated!
df1link todf2? I can't see any matching columns