This is a test version of Biostars. For the public version, visit https://www.biostars.org.
merge two csv files in r (gene to protein pathways)

How can I read in two tab delimited files and map them together by one common column(protein)?

protein_pathway.txt

Pathway                                                        Protein
Binding and Uptake of Ligands by Scavenger Receptors           P69905
Erythrocytes take up carbon dioxide and release oxygen         P69905
Metabolism                                                     P69905
Amyloids                                                       P02647
Metabolism                                                     P02647
Hemostasis                                                     P68871

protein_gene.txt

Gene      Protein
Fabp3     P11404
HBA1      P69905
APOA1     P02647
Hbb-b1    P02088
HBB       P68871
Hba       P01942
datafile1 <- read.csv("c:/gene.csv", header=T, sep=",")
datafile2 <- read.csv("c:/pathway.csv", header=T, sep=",")

dim(datafile1)
dim(datafile2)

datafile <- rbind(datafile1,datafile2)
dim(datafile)

write.csv(datafile,"c:/datafile.csv")

This only gives me the merged (appended one). How can map by a common column protein here?

r

3 answers

help(match)

and help(merge) if you want to to it like a database join

And when merge() gets slow due to absolutely huge datasets:

library(dplyr)
help(left_join)

Merge them by using http://merge-csv.com. You can remove dupcliate headers also.

Use merge:

datafile <-  merge(datafile1, datafile2)

http://www.statmethods.net/management/merging.html

Log in to answer this question.