这是一个多表合并的操作,df1,df2,df3加起来有30行,为什么合并完只有 24 行?去掉那几行的规则是什么?
df1 <- iris[1:10, c(1, 5)]
df2 <- iris[11:15, c(1, 2, 5)]
df3 <- iris[15:30, c(1, 3, 5)]
all_dfs <- list(df1, df2, df3)
# 将所有列都保留 full_join 方式合并
Reduce(function(x, y, ...) merge(x, y, ..., all = TRUE), all_dfs)
#> Sepal.Length Species Sepal.Width Petal.Length
#> 1 4.3 setosa 3.0 NA
#> 2 4.4 setosa NA NA
#> 3 4.6 setosa NA 1.0
#> 4 4.6 setosa NA 1.0
#> 5 4.7 setosa NA 1.6
#> 6 4.8 setosa 3.4 1.9
#> 7 4.8 setosa 3.0 1.9
#> 8 4.9 setosa NA NA
#> 9 4.9 setosa NA NA
#> 10 5.0 setosa NA 1.6
#> 11 5.0 setosa NA 1.6
#> 12 5.0 setosa NA 1.6
#> 13 5.0 setosa NA 1.6
#> 14 5.1 setosa NA 1.5
#> 15 5.1 setosa NA 1.4
#> 16 5.1 setosa NA 1.7
#> 17 5.1 setosa NA 1.5
#> 18 5.2 setosa NA 1.4
#> 19 5.2 setosa NA 1.5
#> 20 5.4 setosa 3.7 1.3
#> 21 5.4 setosa 3.7 1.7
#> 22 5.7 setosa NA 1.7
#> 23 5.7 setosa NA 1.5
#> 24 5.8 setosa 4.0 1.2
sessionInfo()
#> R version 3.6.2 (2019-12-12)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 16.04.6 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/openblas-base/libblas.so.3
#> LAPACK: /usr/lib/libopenblasp-r0.2.18.so
#>
#> locale:
#> [1] LC_CTYPE=zh_CN.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=zh_CN.UTF-8 LC_COLLATE=zh_CN.UTF-8
#> [5] LC_MONETARY=zh_CN.UTF-8 LC_MESSAGES=zh_CN.UTF-8
#> [7] LC_PAPER=zh_CN.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=zh_CN.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods
#> [7] base
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_3.6.2 magrittr_1.5 tools_3.6.2 htmltools_0.4.0
#> [5] yaml_2.2.1 Rcpp_1.0.3 stringi_1.4.5 rmarkdown_2.1
#> [9] highr_0.8 knitr_1.26 stringr_1.4.0 xfun_0.12
#> [13] digest_0.6.23 rlang_0.4.4 evaluate_0.14
<sup>Created on 2020-02-06 by the reprex package (v0.3.0)</sup>