Merging more than 2 csv files in R
2
0
Entering edit mode
8.7 years ago
oqp5041 • 0

Hello!

How do I merge more than two csv files in R based on gene_id and log2.fold_change? Is there a easy code or package for it? Thank you.

merge r • 5.0k views
ADD COMMENT
0
Entering edit mode

I believe the standard way to do this is by successively merging into a resulting dataframe. That is, if you wish to merge e.g. [1,2,3,4,5], you'd do merge(1, merge(2, merge(3, merge(4, 5) ) ) ). This is actually supported explicitly in Pandas — one place where I wish R's dataframes had the same built-in capabilities.

ADD REPLY
0
Entering edit mode
ADD REPLY
3
Entering edit mode
8.7 years ago

The fastest way to do this is with the dplyr package. This follows the same procedure as Rob mentioned in his comment above, but using dplyr::inner_join() is much faster.

ADD COMMENT
1
Entering edit mode
20 months ago
Ram 44k

Adding an updated answer for completeness' sake

The way I do this is using lapply and Reduce

dat.files <- list.files("*.csv") #whatever you need to get the files listed
dat <- lapply(dat.files, read.table, sep=",", ...)
## Now process dat so column names are consistent etc. - you might need a loop
## Once done,

dat <- Reduce(merge, dat) # or Reduce(dplyr::inner_join, dat)
ADD COMMENT

Login before adding your answer.

Traffic: 2822 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6