我有一些文件
file_analysis = read.xlsx(listfiles[1],sheetIndex = 1,header = FALSE)###
#View(file_analysis)
str(file_analysis)
file_comments = read.csv("C:/Users/adm/Downloads/comments.csv",sep=";")
#View(file_comments)
file_groups = read.xlsx(listfiles[6],sheetIndex = 1,header = FALSE) ####
#View(file_groups)
file_headeers = read.xlsx(listfiles[7],sheetIndex = 1,header = FALSE)
file_photos = read.csv("C:/Users/adm/Downloads/photos.csv",sep=";")
#View(file_photos)
file_profiles = read.xlsx(listfiles[12],sheetIndex = 1,header = FALSE) ####
#View(file_profiles)
file_profiles3 = read.xlsx(listfiles[13],sheetIndex = 1,header = FALSE)###
#View(file_profiles)
file_statistics = read.csv("C:/Users/adm/Downloads/statistics.csv",sep=";")
#View(file_statistics)
file_videos = read.csv("C:/Users/adm/Downloads/videos.csv",sep=";")
#View(file_videos)
我需要它合并到一个数据集简易
n=merge(file_comments,file_groups,file_photos ,file_profiles,
file_profiles3,file_statistics,
file_videos, by ="owner_id")
但它给我返回错误
Error in fix.by (by.x, x): 'by' must define one or more columns as numbers, names or logical data
这个修复.by时出错(by.x,x(:';由';必须指定唯一有效的列mergedata<-merge(数据集1,数据集2,by.x="personalid"(这个合并数据-修复.by时出错(by.x,x(对我没有帮助。我不知道为什么。
owner_id是数字
示例
258894746
3389571
3389572
3389573
3389574
118850
怎么了?我需要同时加入所有文件。
merge
不接受两个以上的数据帧。您应该使用Reduce
或purrr::reduce
函数递归应用它,请参见此处
基准R
Reduce(function(dtf1, dtf2) merge(dtf1, dtf2, by = "owner_id"),
list(file_comments,file_groups,file_photos ,file_profiles,
file_profiles3,file_statistics,
file_videos)
)
tidyverse
语法
library(dplyr)
library(purrr)
list(file_comments,file_groups,file_photos ,file_profiles,
file_profiles3,file_statistics,
file_videos) %>% reduce(inner_join, by = "owner_id")
顺便说一句,如果你更喜欢左联接而不是内联接(你打算使用的联接(:
- 在
merge
中添加all.x = TRUE
参数 - 在tidyverse溶液中使用
left_join
而不是inner_join