This function "adds" two lists with the same or different names together. For example, if one list is as l1 <- list(a=1, b="XYZ")
and the second is as l2 <- list(a=3, c=FALSE)
, the output will be as list(a = c(1, 3), b = "XYZ", c = FALSE)
. All elements in each list must have names.
Details
If two lists share the same name and these elements have the same class, then they will be merged as-is. If the classes are different, one of them will be coerced to the other (see *Examples*). The output will have elements with the names of all lists.
Examples
# same data types for same named element
l1 <- list(a=1, b="XYZ")
l2 <- list(a=3, c=FALSE)
appendLists(l1, l2)
#> $a
#> [1] 1 3
#>
#> $b
#> [1] "XYZ"
#>
#> $c
#> [1] FALSE
#>
# different data types for same named element
l1 <- list(a=3, b="XYZ")
l2 <- list(a="letters", c=FALSE)
appendLists(l1, l2)
#> $a
#> [1] "3" "letters"
#>
#> $b
#> [1] "XYZ"
#>
#> $c
#> [1] FALSE
#>