Forgot to add that you can specify which column to merge by inside the "merge" function, i.e.: merge(by='id'...)
Best,
Max
Massimiliano S. Tagliamonte
DVM, MSc, PhD
Postdoc Associate
Emerging Pathogens Institute
Department of Pathology
College of Medicine
University of Florida
________________________________________
From: Tagliamonte,Massimiliano S
Sent: Tuesday, June 5, 2018 8:06 AM
To: [log in to unmask]
Subject: Re: Merging multiple dataframes
Hey, Nihal,
How are you doing? Have you had a look at the function "Reduce"?
Something like this:
df1 = data.frame(id=c('1','73','2','10','43'),v1=c(1,2,3,4,5))
df2 = data.frame(id=c('1','73','57','2','10','96'),v2=c(1,2,3,4,5,6))
df3 = data.frame(id=c('73','62'),v3=c(1,2))
df4<- Reduce(function(x, y) merge(x, y, all=TRUE), list(df1, df2, df3))
Please remember to do do sanity checks after using it.
Have a nice day,
Max
Massimiliano S. Tagliamonte
DVM, MSc, PhD
Postdoc Associate
Emerging Pathogens Institute
Department of Pathology
College of Medicine
University of Florida
________________________________________
From: UF R Users List <[log in to unmask]> on behalf of El Rouby,Nihal M <[log in to unmask]>
Sent: Tuesday, June 5, 2018 7:39 AM
To: [log in to unmask]
Subject: Merging multiple dataframes
Hello R users,
I'm interested in merging 28 dataframes using R keeping overlapping IDs. Can dplyr inner join do that? or Should I try to figure out a loop?
Thanks,
Nihal
This list strives to be beginner friendly. However, we still ask that you
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
This list strives to be beginner friendly. However, we still ask that you
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
|