merge(mydat, res, dat by.x = "ID", by.y = "seq") This is what i have so far but it is not working.
I assume that you are talking about the merge
function from the base
package.
Then as far as I know you have to do the merge in steps:
first merge data.frame1 with data.frame2 and then merge the result with data.frame3 .
How would that code look like?
Here is an example with extra print statements to illustrate the process.
DF1 <- data.frame(ID=c("A","B","C"), Value = 1:3)
DF2 <- data.frame(Seq = c("B", "A", "C"), Number = 11:13)
DF3 <- data.frame(Seq = c("C", "B", "A"), Number2 = 21:23)
DF1
#> ID Value
#> 1 A 1
#> 2 B 2
#> 3 C 3
DF2
#> Seq Number
#> 1 B 11
#> 2 A 12
#> 3 C 13
DF3
#> Seq Number2
#> 1 C 21
#> 2 B 22
#> 3 A 23
AllDat <- merge(DF1, DF2, by.x = "ID", by.y = "Seq")
AllDat
#> ID Value Number
#> 1 A 1 12
#> 2 B 2 11
#> 3 C 3 13
AllDat <- merge(AllDat, DF3, by.x = "ID", by.y = "Seq")
AllDat
#> ID Value Number Number2
#> 1 A 1 12 23
#> 2 B 2 11 22
#> 3 C 3 13 21
Created on 2022-04-09 by the reprex package (v2.0.1)
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.