Question: Merge two columns dataframes
0
gravatar for samira.reuscher
4 weeks ago by
samira.reuscher0 wrote:

Hello, i have a question concerning two dataframe that should be merged. To make it more understandable, I broke it down on a simple example.

tabelle1 <- data.frame(genID = c("a","b","c"), 
                  log2FC = c(11,22,33))
tabelle2 <- data.frame(genID = c("b","c","d"), 
                   log2FC = c(44,55,66))

The new dataframe should consist of 3 columns (genID, log2FCtabelle1, log2FCtabelle2) and four rows (a,b,c,d). Missing values should be marked with NA ...

I hope someone can hep me! Thanks.

R gene • 117 views
ADD COMMENTlink modified 4 weeks ago by zx87548.3k • written 4 weeks ago by samira.reuscher0

Relevant SO post:

ADD REPLYlink written 4 weeks ago by zx87548.3k
2
gravatar for ATpoint
4 weeks ago by
ATpoint24k
Germany
ATpoint24k wrote:

You can use the base function merge like:

merge(tabelle1, tabelle2, by.x = "genID", by.y = "genID", all = TRUE)

genID log2FC.x log2FC.y
a       11       NA
b       22       44
c       33       55
d       NA       66

The by.x/y arguments take the column name of the respective data.frames that shall be used for merging. all=TRUE means to replace missing values by NA.

ADD COMMENTlink modified 4 weeks ago • written 4 weeks ago by ATpoint24k
0
gravatar for nterhoeven
4 weeks ago by
nterhoeven110
nterhoeven110 wrote:

You can do this with left_join() from the tidyverse package

You should rename the log2FC columns to different names and then run left_join(tabelle1,tabelle2). This will merge the two data frames by the common column (genID).

Take a look at https://stat545.com/join-cheatsheet.html for more info about the different join commands

ADD COMMENTlink written 4 weeks ago by nterhoeven110
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2254 users visited in the last hour