[R] Merging multiple .csv files

R. Michael Weylandt michael.weylandt at gmail.com
Wed Apr 11 15:10:46 CEST 2012


Simply pass all = FALSE to merge_all

merge_all(list_of_files, by = "Name", all = FALSE)

Michael

On Wed, Apr 11, 2012 at 1:09 AM, Chintanu <chintanu at gmail.com> wrote:
> Thanks to David and Michael
>
> Michael:
>
> That works, however with a glitch. Each of my 24 files has got two columns:
> "Name", and "Rank/score".
>
> file_list <- list.files()
> list_of_files <- lapply(file_list, read.csv) # Read in each file
>
> # I can see the 2-columns at this stage. However, the following line:
>
> merge_all(list_of_files, by = "Name")
>
> # produces some NAs for the 2nd column (except the beginning 1/3rd of the
> columns which have values). Not sure about the reason - the original files
> don't have  any NAs.
>
>
> Further, I understand that it gives the union of (rows of) files based on
> "Name". Is there a way to look for intersection, i.e., similar to using:
> merge (.... ,by="Name", all=FALSE)  ?
>
>
> David:  It came up with an error :
>
> do.call(merge, list_of_files, by="Name")
>
> Error in do.call(merge, list_of_files, by = "Name") :
>   unused argument(s) (by = "Name")
>
> Cheers,
> Chintanu
>
>



More information about the R-help mailing list