Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine data sets with different IDs for same subjects

I have data sets for four time points of the same subjects. Unfortunately, the subjects have different IDs in those data set. Thus, my data looks something like this:

df1 <- data.frame(ID = c("ALKJAD", "FAJOQF", "PQDJSLC"),
                  v1 = c(1,2,3),
                  V2 = c(4,5,6))


df2 <- data.frame(ID = c("KFOWQP", "QODPFL", "XBCMVB"),
                  v1 = c(2,4,6),
                  V2 = c(5,7,9))

df3 <- data.frame(ID = c("DWTHKU", NA, "SCBFHT"),
                  v1 = c(3, NA, 9),
                  V2 = c(4, NA, 8))

dfID <- data.frame(ID_t1 = c("ALKJAD", "FAJOQF", "PQDJSLC"),
                   ID_t2 = c("KFOWQP", "QODPFL", "XBCMVB"),
                   ID_t3 = c("DWTHKU", NA, "SCBFHT"))

How can I combine the four data sets based on this list?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could do two joins (although difficult to say if this code works without reproducible data).

library(dplyr)
inner_join(df1, df_ID, by = c("ID" = "ID_t1")) %>%
   inner_join(., df2, by = c("ID_t2" = "ID"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading