Merge multiple data frames by row names, or do other versions of database join operations.
Arguments
- ...
data frames to be coerced to one.
- all.x
logical; if
TRUE, then extra rows will be added to the output, one for each row in x that has no matching row in y. These rows will haveNAs in those columns that are usually filled with values from y. The default isTRUE, so that non-matching rows are kept and padded withNAs (full outer join).- all.y
logical; analogous to
all.x.- by
column used for merging, if this is not defined rownames will be used by default. The column must be included in all the provided data frames and its values must be unique within each data frame. Note that the restored key column is of type character.
Value
a data frame. The rows are sorted according to the appearance of previously unobserved rownames. So the rownames appearing in the first data frame are first, then the rownames in the second data frame, which have no corespondence in the first data frame and so on. The columns are the remaining columns in x1 and then those in x2 and then those in x3. The result has the row names resulting from the merge.
See also
Other data.append:
appendEnum(),
appendRowNames(),
appendX()
Examples
x1 <- setNamesX(data.frame(v = letters[1:6], w = 1:6),
rownames = LETTERS[1:6])
x2 <- setNamesX(data.frame(v = letters[2:4], ww = 11:13),
rownames = LETTERS[2:4])
x3 <- setNamesX(data.frame(v = letters[c(1, 3, 5, 7, 10)], wwww = 22:26),
rownames = LETTERS[c(1, 3, 5, 7, 10)])
# the default merges on the row names and returns their union,
# with NA wherever a frame has no such row
multMerge(x1, x2, x3)
#> v w v.1 ww v.2 wwww
#> A a 1 <NA> NA a 22
#> B b 2 b 11 <NA> NA
#> C c 3 c 12 c 23
#> D d 4 d 13 <NA> NA
#> E e 5 <NA> NA e 24
#> F f 6 <NA> NA <NA> NA
#> G <NA> NA <NA> NA g 25
#> J <NA> NA <NA> NA j 26
# v is not a key in the call above and is simply carried along from
# each frame; here it becomes the key instead
multMerge(x1, x2, x3, by = "v")
#> v w ww wwww
#> 1 a 1 NA 22
#> 2 b 2 11 NA
#> 3 c 3 12 23
#> 4 d 4 13 NA
#> 5 e 5 NA 24
#> 6 f 6 NA NA
#> 7 g NA NA 25
#> 8 j NA NA 26
