【发布时间】:2022-01-23 04:27:45
【问题描述】:
我有一个列表,想创建一个新的列表条目d,方法是将现有列表条目绑定在一起,如下所示:
library(data.table)
## this works fine
example_list <- list("a" = data.frame(x = 1),
"b" = data.frame(x = 2),
"c" = data.frame(x = 3))
example_list[["d"]] <- rbindlist(example_list[c("a", "b", "c")])
是否可以在创建原始列表的同时创建d?我想做这样的事情:
## this does not work
example_list <- list("a" = data.frame(x = 1),
"b" = data.frame(x = 2),
"c" = data.frame(x = 3),
"d" = rbindlist(.[c("a", "b", "c")]))
编辑:我需要明确引用以前的列表条目,因此这样的事情不起作用:
## ineligible
example_list <- list("a" = data.frame(x = 1),
"b" = data.frame(x = 2),
"c" = data.frame(x = 3),
"d" = data.frame(x = 1) %>%
rbind(data.frame(x = 2)) %>%
rbind(data.frame(x = 3)))
【问题讨论】:
标签: r