【发布时间】:2019-08-31 01:46:18
【问题描述】:
我有两个数据框,每个数据框有两列我想比较,并生成出现在第一个数据框中的输出,这只是数据框之间比较时两列交互的差异。
我尝试使用合并、%in%、交互、匹配,但似乎无法获得正确的输出。我也在 SO 上进行了广泛的搜索,但没有发现类似的问题。
我找到的最接近的回复是:
newdat <- match(interaction(dfA$colA, dfA$colB), interaction(dfB$colA, dfB$colB))
但显然,这段代码不正确,因为它(如果工作)会给我一些数据帧之间共有的东西,我想要它们之间的区别(错误 - 它生成一个数字向量,当 colA 和B 是字符串)。
示例数据:
#Dataframe A
colA colB
Aspirin Smith, John
Aspirin Doe, Jane
Atorva Smith, John
Simva Doe, Jane
#Dataframe B
colA colB
Aspirin Smith, John
Aspirin Doe, Jane
Atorva Doe, Jane
## GOAL:
#Dataframe
colA colB
Atorva Smith, John
Simva Doe, Jane
谢谢!
【问题讨论】: