Reputation: 1201
I want to create a list container to store a number of other different lists. My code looks like
temp = list()
list1 = list(a=1)
list2 = list(b=2)
list3 = list(c=c(1,2), d=c(4,5))
temp[1] = list1
temp[2] = list2
temp[3] = list3
Warning message: In temp[3] = list3 : number of items to replace is not a multiple of replacement length. It seems that all lists should have same length. How can I overcome this problem?
Upvotes: 2
Views: 48
Reputation: 206167
If you want to work with elements in lists, you use [[]]
when you want to change the list itself, you use []
temp = list()
list1 = list(a=1)
list2 = list(b=2)
list3 = list(c=c(1,2), d=c(4,5))
temp[[1]] = list1
temp[[2]] = list2
temp[[3]] = list3
Upvotes: 1