library(tidyverse)
我有这个DFS列表:
my_list <- list(structure(list(observations = c(1L, 5L), variables = c(4L,
8L)), class = "data.frame", row.names = c("asp_202003...Copy.xlsx",
"asp_202003.xlsx")), structure(list(observations = c(3L, 1L),
variables = 5:4), class = "data.frame", row.names = c("eay_201008_a.xlsx",
"eay_202003.xlsx")), structure(list(observations = 3:4, variables = c(4L,
6L)), class = "data.frame", row.names = c("wana_202309...Copy.xlsx",
"wana_202309.xlsx")))
我按如下方式合并DFS:
my_merge <- my_list %>% reduce(full_join)
输出: 我的合并(_M)
# observations variables
#1 1 4
#2 5 8
#3 3 5
#4 3 4
#5 4 6
但我希望将索引名保留(或提取)在名为‘FILE’的新列中,如下所示:
请注意,情况并非如此.
# file observations variables
# asp_202003...Copy.xlsx 1 4
# asp_202003.xlsx 5 8
# etc.
还要注意,所需的输出应该有6行,而不是当前my_merge对象中的5行!在当前my_merge对象中,两行之间的值相同意味着其中一行"丢失".这也是为什么我想将文件名设置为索引.