【发布时间】:2019-12-05 05:29:30
【问题描述】:
我有一个这样的列表:
list=list(
df1=read.table(text = "a b c
11 14 20
17 15 12
6 19 17
",header=T),
df2=read.table(text = "a b c
6 19 12
9 7 19
",header=T),
df3=read.table(text = "a d f
12 20 15
12 10 8
7 8 7
",header=T),
df4=read.table(text = "g f e z
5 12 11 5
16 17 20 16
19 9 11 20
",header=T),
df5=read.table(text = "g f e z
15 13 9 18
12 12 17 16
15 9 12 11
15 20 19 15
",header=T),
df6=read.table(text = "a d f
11 7 16
11 12 11
",header=T)
)
我的列表包含不同的数据框。根据列名,列表中有 3 种类型的数据框。
type1:df1 and df2
type2:df3 and df6
type3:f4 and df5
我要去rbind 具有相同列名的数据框并将结果保存在新列表中。例如 df1 与 df2、df3 与 df6 以及 df4 与 df5 具有相同的列名。我需要一个自动识别和rbind 具有相同列名的数据帧的代码。
预期结果如下:
> new list
$df1.df2
a b c
1 11 14 20
2 17 15 12
3 6 19 17
4 6 19 12
5 9 7 19
$df3.df6
a d f
1 12 20 15
2 12 10 8
3 7 8 7
4 11 7 16
5 11 12 11
$df4.df5
g f e z
1 5 12 11 5
2 16 17 20 16
3 19 9 11 20
4 15 13 9 18
5 12 12 17 16
6 15 9 12 11
7 15 20 19 15
新列表中数据框的名称可以是任何名称。
【问题讨论】:
-
dplyr::bind_rows(dfls)起点 -
dplyr::bind_rows(dfls)rbind 所有数据帧。我需要重新绑定相同的数据帧。