Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

use append() and get() to form list of lists

$
0
0

I have a list of list names and corresponding lists like this:

list_names <- list("name1", "name2", "name3")
name1 <- list("apple", "banana", "orange", "peach")
name2 <- list("foo", "bar", "baz")
name3 <- list("house", "tree")

I now want to create a list of lists, with each list entry containing one of the lists name1 - name3.

I tried the following code unsuccessfully but am stuck:

list_of_lists <- list()
for (i in 1:length(list_names)){
    ls <- list_names[[i]]
    append(list_of_lists, get(ls))
    }

The code runs without errors but list_of_lists us a List of 0, while I expect it to look like this:

> list_of_lists
$name1
$name1[[1]]
[1] "apple"
$name1[[2]]
[1] "banana"
$name1[[3]]
[1] "orange"
$name1[[4]]
[1] "peach"
$name2
$name2[[1]]
[1] "foo"
$name2[[2]]
[1] "bar"
$name2[[3]]
[1] "baz"
$name3
$name3[[1]]
[1] "house"
$name3[[2]]
[1] "tree"

What am I missing?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>