0

I have imported several groups of .csv files in R, and named them as follows:

DEMO, DEMO_B, DEMO_C, DEMO_D
DIQ, DIQ_B, DIQ_C, DIQ_D
MCQ, MCQ_B, MCQ_C, MCQ_D
MORT, MORT_B, MORT_C, MORT_C

I would like to to create a series of new dataframes as follows:

Merg = DEMO + DIQ + MCQ + MORT
Merg_B = DEMO_B + DIQ_B + MCQ_B + MORT_B
...

I have done it step by step, but it is too anoying to change names one by one, and would better to have a loop or function, thanks guys!

Merg <- DEMO %>%
dplyr::left_join(DIQ, by = join_by(SEQN == SEQN)) %>%
dplyr::left_join(MCQ, by = join_by(SEQN == SEQN)) %>%
dplyr::left_join(Mort, by = join_by(SEQN == SEQN)) %>%
dplyr::select(1:7,9:12)
colebrookson
  • 831
  • 7
  • 18
  • Essentially what you're trying to do is left-join a series of dataframes. @Akrun has answered a very similar question to this [here](https://stackoverflow.com/questions/32066402/how-to-perform-multiple-left-joins-using-dplyr-in-r) – colebrookson Apr 30 '23 at 08:26

0 Answers0