【发布时间】:2019-01-30 19:48:30
【问题描述】:
我有两个数据帧 dat1 和 dat2,我想在两个数据帧的前两列之间找到匹配项,并将每个数据帧中包含的值连接成唯一对。
dat1<-data.frame(V1 = c("home","fire","sofa","kitchen"),
V2 = c("cat","water","TV","knife"), V3 = c('date1','date2','date3','date4'))
V1 V2 V3
1 home cat date1
2 fire water date2
3 sofa TV date3
4 kitchen knife date4
dat2<-data.frame(V1 = c("home","water","sofa","knife"),
V2 = c("cat","fire","TV","kitchen"), V3 = c('col1','col2','col3','col4'))
V1 V2 V3
1 home cat col1
2 water fire col2
3 sofa TV col3
4 knife kitchen col4
所需的结果是:
V1 V2 V3 V4
1 home cat date1 col1
2 water fire date2 col2
3 sofa TV date3 col3
4 knife kitchen date4 col4
你知道如何在 R 中做到这一点吗?
【问题讨论】: