我想创建一个列表容器来存储许多其他不同的列表。我的代码看起来像
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
警告讯息: 在temp [3] = list3中: 要更换的项目数不是更换长度的倍数。似乎所有列表都应该具有相同的长度。我怎样才能克服这个问题?
答案 0 :(得分:0)
如果您想使用列表中的元素,当您想要更改列表本身时使用[[]]
,则使用[]
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