Merging more than 2 dataframes in R by rownames

后端 未结 4 2023
醉梦人生
醉梦人生 2020-12-04 19:28

I gather data from 4 df\'s and would like to merge them by rownames. I am looking for an efficient way to do this. This is a simplified version of the data I have.

4条回答
  •  青春惊慌失措
    2020-12-04 20:06

    Editing your function, I have came up with the function which allows you to merge more data frames by a specific column key (name of the column). The resulted data frame includes all the variable of the merged data frames (if you wanna keep just the common variables (excluding NA, use: all.x= FALSE, all.y= FALSE)

    MyMerge <- function(x, y){
      df <- merge(x, y, by= "name of the common column", all.x= TRUE, all.y= TRUE)
      return(df)
    }
    new.df <- Reduce(MyMerge, list(df1, df2, df3, df4))
    

提交回复
热议问题