在R中读取文件时,如何同时执行两个操作?

在R中读取文件时,如何同时执行两个操作?,r,csv,R,Csv,我有一个CSV文件- 数据1.csv BusinessNeedParent,BusinessNeedChild,Identifier a1,b1,45 a2,b2,60 a3,b3,56 数据2.csv IndustryFoccusParent,IndustryFocusChild,Identifier x1,y1,75 x2,y2,66 x3,y3,78 数据3.csv AdvertiserName,BusinessNeedNumber,IndustryFocusNumber,State,

我有一个CSV文件-

数据1.csv

BusinessNeedParent,BusinessNeedChild,Identifier
a1,b1,45
a2,b2,60
a3,b3,56
数据2.csv

IndustryFoccusParent,IndustryFocusChild,Identifier
x1,y1,75
x2,y2,66
x3,y3,78
数据3.csv

AdvertiserName,BusinessNeedNumber,IndustryFocusNumber,State,City
worker,45,75,Calif,Los angeles
workplace,45,66,Calif,San Diego
platoon,60,66,Connec,Bridgeport
teracota,56,78,New York,Albany
worker,45,66,Calif,Los Angeles


AdvertiserName,BusinessNeedParent,BusinessNeedChild,IndustryFocusParent,IndustryFocusChild,State,City
worker,a1,b1,x1,y1,Calif,Los angeles
workplace,a1,b1,x2,y2,Calif,San Diego
platoon,a2,b2,x2,y2,Connec,Bridgeport
teracota,a3,b3,x3,y3,New York,Albany
worker,a2,b2,x2,y2,Calif,Los Angeles
我想从Data1.csv和Data2.csv中匹配标识符、BusinessNeedNumber和IndustryFocusNumber,以获得上述输出

到目前为止,代码是这样的-

record <- read.csv("Data3.csv",header=TRUE)
businessneedinformation <- read.csv("Data1.csv",header=TRUE)
industryFocusinformation <- read.csv("Data2.csv",header=TRUE)
record您可以尝试:

m <- merge(Data1,Data3,by.x="Identifier",by.y="BusinessNeedNumber", all.y=TRUE)
#use m instead of Data3
n <- merge(Data2,m,by.x="Identifier",by.y="IndustryFocusNumber", all.y=TRUE)

m您只能在基本R中使用
merge
执行两个数据帧。请尝试使用
plyr
包中的
join\u all
功能,或者如果您知道sql,请尝试使用
sqldf
包。我突然想到我可以给你举个例子。嘿,漫长的一天
m <- merge(Data1,Data3,by.x="Identifier",by.y="BusinessNeedNumber", all.y=TRUE)
#use m instead of Data3
n <- merge(Data2,m,by.x="Identifier",by.y="IndustryFocusNumber", all.y=TRUE)