首页 > 解决方案 > 将R中的数据框与名称水平组合

问题描述

我有一组 12 个数据帧(DF1、DF2、... DF12),格式类似:

> DF1
# A tibble: 12 x 6
   month     mean  max   min   sd        n
   <chr>     <chr> <chr> <chr> <chr> <int>
 1 January   1.22    x     x     x      x
 2 February  2.23    x     x     x      x
 3 March     4.86    x     x     x      x
 4 April     7.82    x     x     x      x
 5 May        -      -     -     -      x
 6 June       -      -     -     -      x
 7 July       -      -     -     -      x
 8 August     -      -     -     -      x
 9 September  -      -     -     -      x
10 October    -      -     -     -      x
11 November   -      -     -     -      x
12 December   -      -     -     -      x

数据框总是相似的(12X6),列名也是相似的(月、平均值、最大值、最小值、标准差、n)。如何水平组合 12 个数据帧以获得类似的东西(上面有 DF 的名称):

                   "name of the DF1"                           "name of the DF2"                 "name of the DF3"             ....
   month     mean.x max.x min.x sd.x n.x   mean.y       max.y       min.y sd.y n.y
1  January      -     -     -    -   -    -           -           -    -   -
2  February     -     -     -    -   -    -           -           -    -   -
3  March        -     -     -    -   -    -           -           -    -   -
4  April        -     -     -    -   -    -           -           -    -   -
5  May          -     -     -    -   -    -           -           -    -   -
6  June         -     -     -    -   -    -           -           -    -   -
7  July         -     -     -    -   -    -           -           -    -   -
8  August       -     -     -    -   -    -           -           -    -   -
9  September    -     -     -    -   -    -           -           -    -   -
10 October      -     -     -    -   -    -           -           -    -   -
11 November     -     -     -    -   -    -           -           -    -   -
12 December     -     -     -    -   -    -           -           -    -   -

我有一个包含我的 12 个数据框的列表:

var_names <- ls(envir = globalenv(), pattern = "^Final_analysis")
DF<- mget(var_names)

标签: rlistmerge

解决方案


dplyr::bind_cols(DF)可以做到这一点。


推荐阅读