简体   繁体   中英

a list to store different lists

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM