[R] Merging multiple .csv files
David Winsemius
dwinsemius at comcast.net
Wed Apr 11 06:30:35 CEST 2012
On Apr 11, 2012, at 12:17 AM, R. Michael Weylandt wrote:
> 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")
or (untested) but not needing reshape
MMM <- do.call(merge, list_of_files, by="Name")
--
David.
>
> 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.
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list