这个问题与此有关
How to loop over the columns in a dataframe, apply spread, and create a new dataframe in R?
我有一个包含3个tibbles的列表:
$Peter
# A tibble: 3 x 4
date Peter Ben Mary
<chr> <dbl> <dbl> <dbl>
1 2020-03-30 0.4 NA NA
2 2020-10-14 NA 0.6 NA
3 2020-12-06 NA NA 0.7
$Ben
# A tibble: 3 x 4
date Peter Ben Mary
<chr> <dbl> <dbl> <dbl>
1 2020-03-30 0.5 NA NA
2 2020-10-14 NA 0.4 NA
3 2020-12-06 NA NA 0.2
$Mary
# A tibble: 3 x 4
date Peter Ben Mary
<chr> <dbl> <dbl> <dbl>
1 2020-03-30 0.2 NA NA
2 2020-10-14 NA 0.1 NA
3 2020-12-06 NA NA 0.9
mylistdf <- list(Peter = structure(list(date = c("2020-03-30", "2020-10-14",
"2020-12-06"), Peter = c(0.4, NA, NA), Ben = c(NA, 0.6, NA),
Mary = c(NA, NA, 0.7)), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame")), Ben = structure(list(date = c("2020-03-30",
"2020-10-14", "2020-12-06"), Peter = c(0.5, NA, NA), Ben = c(NA,
0.4, NA), Mary = c(NA, NA, 0.2)), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame")), Mary = structure(list(date = c("2020-03-30",
"2020-10-14", "2020-12-06"), Peter = c(0.2, NA, NA), Ben = c(NA,
0.1, NA), Mary = c(NA, NA, 0.9)), row.names = c(NA, -3L), class = c("tbl_df",
"tbl", "data.frame")))
如何在全球环境中将这3个tibble全部保存为自己的tibble:
预期输出将有点像Peter、Ben、Mary在全球环境中作为tibble或数据帧。
我知道我们可以做到:
Peter <- mylistdf$Peter
Ben <- mylistdf$Ben
Mary <- mylistdf$Mary
但我想用地图或类似的东西一次性完成:
mylistdf %>%
.....