[R] Merging multiple .csv files

R. Michael Weylandt michael.weylandt at gmail.com
Wed Apr 11 06:17:09 CEST 2012


Your problem is that you can't merge the file names, but you need to
load them into R and merge the resulting objects.

This should be straightforward enough to do:

file_list <- list.files()
list_of_files <- lapply(file_list, read.csv) # Read in each file
merge_all(list_of_files, by = "Name")

Michael

On Wed, Apr 11, 2012 at 12:08 AM, Chintanu <chintanu at gmail.com> wrote:
> Hi all,
>
> I wish to merge 24 .csv files, each having a common identifier-column
> ("Name") and do two things:
>
> 1. Retrieve the common one's. [Analogy: while merging 2-dataframes, similar
> to using: merge (.... ,by="Name", all=FALSE) ]
>
> 2. Retrieve all, i.e., the union of the rows of 24 files.  [again, somthing
> like:  merge (.... ,by="Name", all=TRUE)  ]
>
>
> On the web, I could see a few ways people seem to merge more than 2
> dataframes.
>
> I tried to use library (reshape), but it didn't bring any result:
>
>  file_list <- list.files()
>  m <- merge_all (file_list, by="Name")
>
> Any help would be appreciated.
>
> Thank you.
>
> regards,
> Chintanu
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list