merge.list merges two lists. If there are identical names in
both lists, only the elements of the first list are considered.
## S3 method for class 'list' merge(x, y = NULL, mergeUnnamed = TRUE, ...)
a list of possibly named elements. All of these are in the merged list.
a list of possibly named elements or any object,
which can be coerced to
arguments to be passed to or from methods.
The purpose of this function is to merge two lists (e.g. argument lists). If a named element is found as well in the first list as in the second, only the value of the element in the first list is considered. One can think of the second list as a list of default values, which should be considered only if they are not set explicitly in the first list.
Unnamed elements in
y are included in the merged list
a list containing all elements of the argument
y having names not occuring in
merge(list(a=1, b="test"), list(3, b=2)) # list(a=1, b="test", 3) merge(list(1), "test") # list(1, "test") merge(list(1), "test", FALSE) # list(1) merge(list(1)) # list(1) merge(list(1, a=2, b=3), list(2, b=4)) # list(1, a=2, b=3, 2) merge(list(1), list(2, b=3), FALSE) # list(1, b=3) a <- list(1, 2, 3) b <- list("a", "b", "c") names(a) <- names(b) <- "z" all.equal(merge(a, b), list(1, z=2, 3, "a", "c")) # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.