简体   繁体   中英

Merging dataframes in R

I have two dataframes which I would like to merge based on a common column

 [dataset A][http://public.justcloud.com/dldzm0fnsp.4540049] 

 [dataset B][http://public.justcloud.com/dldzmx1758.4540049]

Using

    merged terms <- dd_B[dd_B$GOBPID %in% dd_A$GOBPID,]

gives me the following error

    <0 rows> (or 0-length row.names)

I already tried using merge as well which gives me the same error.

I'm going to guess that you used read.csv on these files. However, if you opened the files in a decent text editor, you would see that these are actually tab-delimited files, so the more appropriate tool would be read.delim .

Here's what I did:

df1 <- read.delim("~/Downloads/dd_a.csv", strip.white = TRUE)
df2 <- read.delim("~/Downloads/dd_B.csv", strip.white = TRUE)
out <- merge(df2, df1)

head(out)
#       GOBPID Pvalue OddsRatio ExpCount Count Size                                         Term
# 1 GO:0000038  0.036     7.008        0     2   49 very long-chain fatty acid metabolic process
# 2 GO:0006412  0.013     2.704        3     8  510                                  translation
# 3 GO:0006413  0.001    11.556        0     4   62                     translational initiation
# 4 GO:0006414  0.022     9.417        0     2   37                     translational elongation
# 5 GO:0006448  0.036    32.723        0     1    6       regulation of translational elongation
# 6 GO:0006457  0.041     2.753        2     5  308                              protein folding

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM