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

Creating a loop that full jon dataframes in R

I have six dataframes: A2020, B2020, A2021, B2021, A2022, and B2022.

All six dataframes have a common key variable called "id".

I want to do three full_join:

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

  • A2020 and B2020 using "id" as key variable
  • A2021 and B2021 using "id" as key variable
  • A2022 and B2022 using "id" as key variable

As result, I would have three dataframes: AB2020, AB2021, AB2022

I tried this, but R doesn’t recognize A or B dataframes:

for(i in c(2020:2022) {
    A <- get(A[[i]])
    B <- get(B[[i]])
    tmp <- full_join(A,B,by="id")
    assign(paste("AB",i,sep = ""),tmp)
}

>Solution :

How about
A <- get(paste0("A", i)

inside the loop instead of A <- get(A[[i]])

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