R 批量声明列表的清理方法?

R 批量声明列表的清理方法?,r,list,R,List,我有一个迭代过程,涉及将修改/使用的数据附加到列表的子列表。声明一堆列表感觉相当混乱,例如testList您可以使用assign。假设您拥有列表的名称或希望以迭代方式设置它们: for (i in 1:5){ assign(paste0("x",i),list()) } 如果您有以下姓名: listnames = c("testList", "otherTestList","anotherTestList", ...) for (i in 1:5){ assign(li

我有一个迭代过程,涉及将修改/使用的数据附加到列表的子列表。声明一堆列表感觉相当混乱,例如testList您可以使用assign。假设您拥有列表的名称或希望以迭代方式设置它们:

for (i in 1:5){
  assign(paste0("x",i),list())
}
如果您有以下姓名:

listnames = c("testList", "otherTestList","anotherTestList", ...)
    for (i in 1:5){
      assign(listnames[i],list())
    }

这将为您提供5个变量,分别命名为x1、x2或testList、otherTestList。。。每个循环都包含一个空列表。

我犯了一个错误,但它只是表示循环的一种任意行为-谢谢你指出了这一点
listnames = c("testList", "otherTestList","anotherTestList", ...)
    for (i in 1:5){
      assign(listnames[i],list())
    }