r - 合并表列表而不更改标签顺序
问题描述
我正在尝试按第一列合并表列表,但顺序正在改变,我希望行的顺序应该与第一次迭代相同。
so the output of my first function is list of dataframes
df_list1 <- data.frame(c= c("tml 14","tml 26","tml 73","tml 24","tml 95","tml 60","tml 77","tml 8","tml 19"),
"CAD"=c(399,590,287,353,483,591,184,501,590))
df_list2 <- data.frame(c= c("tml 14","tml 26","tml 73","tml 24","tml 95","tml 60","tml 77","tml 8","tml 19"),
"NHA"=c(556,188,446,583,398,505,461,737,164))
df_list3 <- data.frame(c= c("tml 14","tml 26","tml 73","tml 24","tml 95","tml 60","tml 77","tml 8","tml 19"),
"BHS"=c(356,337,712,255,573,598,622,144,159))
df_list4 <- data.frame(c= c("tml 14","tml 26","tml 73","tml 24","tml 95","tml 60","tml 77","tml 8","tml 19"),
"KLI"=c(686,630,627,498,551,159,253,448,437))
my function1 is like
function1 <- df_list2[[i]]<- function(df,var,rownames[i])
df_list[i]<- do.call(rbind,df_list2)
now df is the output list like df1 , df2, df3.......
and I want to join those list of data frames to create one table
and I am trying like below
tbl<-Reduce(function(...)merge(...,all=TRUE,by="C"),df_list)
我们有什么解决方案可以让我保持相同的行顺序...??
输出就像
解决方案
我们可以使用full_join
with reduce
which 将以相同的顺序给出输出
library(dplyr)
library(purrr)
library(stringr)
reduce(mget(str_c('df_list', 1:4)), full_join, by = 'c')
推荐阅读
- git - 尝试使用 SSH 身份验证从 Google Cloud Source Repositories 克隆 repo
- swift - 如何将 indexPath 数组拆分为单独的 indexPath 数组,每个数组的 indexPath 具有相同的 indexPath.section
- jenkins - 从 Jenkinsfile 的另一个阶段调用环境变量
- regex - 使用正则表达式捕捉莎士比亚角色的对话
- date - 如何显示格式日期:dd/MM/yyyy 10:05 pm
- amazon-web-services - 有没有办法在 AWS kenesis 中创建类似 Kafka 的主题?
- ios - 类型'NSError'在swift 4中没有成员'errorWith'?
- html - 浏览器鼠标按下(并按住)然后将光标对象拖出边界,对象边框变为蓝色,我该如何控制?
- kubernetes - Kubernetes pod 无法访问外部 IP 地址
- react-native - 在 react-native 中保持用户身份验证的最佳方法