Mam dwie listy, których elementy mają częściowo pokrywających się nazwiska, które trzeba połączyć/połączyć ze sobą w jednej listy, element po elemencie:Kombajny/scalić list elementami nazw
> lst1 <- list(integers=c(1:7), letters=letters[1:5],
words=c("two", "strings"))
> lst2 <- list(letters=letters[1:10], booleans=c(TRUE, TRUE, FALSE, TRUE),
words=c("another", "two"), floats=c(1.2, 2.4, 3.8, 5.6))
> lst1
$integers
[1] 1 2 3 4 5 6 7
$letters
[1] "a" "b" "c" "d" "e"
$words
[1] "two" "strings"
> lst2
$letters
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
$booleans
[1] TRUE TRUE FALSE TRUE
$words
[1] "another" "two"
$floats
[1] 1.2 2.4 3.8 5.6
Próbowałem za pomocą mapply, który zasadniczo łączy dwie listy według indeksu (tj .: "[["), , podczas gdy muszę połączyć je według nazwy (tj .: "$"). Ponadto, ponieważ listy mają różne długości, stosowana jest reguła recyklingu (z raczej nieprzewidywalnymi wynikami).
> mapply(c, lst1, lst2)
$integers
[1] "1" "2" "3" "4" "5" "6" "7" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
$letters
[1] "a" "b" "c" "d" "e" "TRUE" "TRUE" "FALSE" "TRUE"
$words
[1] "two" "strings" "another" "two"
$<NA>
[1] 1.0 2.0 3.0 4.0 5.0 6.0 7.0 1.2 2.4 3.8 5.6
Warning message:
In mapply(c, lst1, lst2) :
longer argument not a multiple of length of shorter
Jak można sobie wyobrazić, co szukam jest:
$integers
[1] 1 2 3 4 5 6 7
$letters
[1] "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
$words
[1] "two" "strings" "another" "two"
$booleans
[1] TRUE TRUE FALSE TRUE
$floats
[1] 1.2 2.4 3.8 5.6
Czy istnieje jakiś sposób, aby to osiągnąć? Dziękujemy!