Merge multiple data frames, given in a list
Arguments
- dataFrames
list of data frames. If the list elements are named, the element names are used as suffixes in the column names, otherwise suffixes ".1", ".2", etc are used
- by
vector of column names to be merged by, passed on to
merge
- ...
additional arguments passed to
merge
- dbg
if
TRUE
(default) debug messages showing the process of merging are shown
Value
data frame being the result of merging all the data frames given in
dataFrames by consecutively calling merge
Examples
peter <- data.frame(fruit = c("apple", "pear", "banana"), kg = 1:3)
paul <- data.frame(fruit = c("banana", "apple", "lemon"), kg = c(10, 20, 30))
mary <- data.frame(fruit = c("lemon", "organger", "apple"), kg = c(22, 33, 44))
# By default only categories that are in all data frames are returned
mergeAll(list(peter = peter, paul = paul, mary = mary), by = "fruit")
#> merging table 2 / 3 ... ok.
#> merging table 3 / 3 ... ok.
#> fruit kg.peter kg.paul kg.mary
#> 1 apple 1 20 44
# Use the arguments supported by merge to change that behaviour
mergeAll(list(peter = peter, paul = paul, mary = mary), by = "fruit", all = TRUE)
#> merging table 2 / 3 ... ok.
#> merging table 3 / 3 ... ok.
#> fruit kg.peter kg.paul kg.mary
#> 1 apple 1 20 44
#> 2 banana 3 10 NA
#> 3 lemon NA 30 22
#> 4 organger NA NA 33
#> 5 pear 2 NA NA