0
我想从字符串创建多个列表。例如,处理一些数据和图表时,我想保持列表中的我的工作流整洁和存储对象:从字符串创建多个列表
# For data
lstDta <- list()
# For charts
lstChrts <- list()
以同样的方式创建多个列表看起来枯燥,重复的,这是不愉快的眼睛。
问题
理想情况下,我想创建一个使用与名称的字符串列表:
mapply(assign, c("lstDta", "lstChrts"),
rep(as.list(1),3), pos = 1)
理解,下面的代码返回错误:
> mapply(assign, c("lstDta", "lstChrts"),
+ rep(as.list(NULL),2), pos = 1)
Error in mapply(assign, c("lstDta", "lstChrts"), rep(as.list(NULL), 2), :
zero-length inputs cannot be mixed with those of non-zero length
这将是可能的让它运行,就像那样:
mapply(assign, c("lstDta", "lstChrts"),
rep(as.list(1),2), pos = 1)
但创建的对象是numeric
。我想达到的结果归结为:取这个字符向量并为每个值创建一个空列表。
@nrussell就像一个魅力 – Konrad
仅供参考,分配链,所以,如果你只是想做到简明扼要(而非动态)'L1 = L2 = L3 =列表()' –