Reputation: 617
given that I have a vector: x <- c("m1", "m2", "m3") and every element m1, m2 and m3 is a list e.g.
m1 = list(a=1:3, b=2:4, c=1:10)
m2 = list(a=0:3, b=0:4, c=6:10)
m3 = list(a=1:30, b=1:2, c=6:10)
I want to be able to create "super list" using loop:
mylist <- list()
for(i in x)mylist[[i]] <- ...??....
when i="m1"
then mylist[["m1"]] <- m1
any suggestion would be appreciate.
Robert
Upvotes: 1
Views: 402
Reputation: 57696
It looks like what you're trying to do is, given a vector of object names, combine the given objects into a list.
mylist <- lapply(x, get)
names(mylist) <- x
Upvotes: 3