This is a test version of Biostars. For the public version, visit https://www.biostars.org.
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.

r

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.

Log in to answer this question.