How to merge 2 dataframes based on common column names?
Hi,
I have two data frames, both containing the columns GeneName and logFC.
Using intersect(), I have obtained the common genes between the two. I want to know how to merge my two dataframes based on the common dataframe.
Thank you.
• 7,767 views
•
link
1 answer
1. Get common column names
common_column_names <- intersect(names(dataframe_1), names(dataframe_2))
2. Use this character vector as your by parameters in the merge function.
merge(dataframe_1, dataframe_2, by=common_column_names, all.dataframe_1=TRUE)
** P.S - Your title of the question should be "How to merge 2 dataframes based on common column names?" I have edited the title.
• 0 views
•
link
Log in to answer this question.