通过三列连接两个数据框,并仅保留匹配的数据框

时间:2020-09-04 17:02:40

标签: r dataframe join

我有两个数据框: dt1:

     Date                Type1   Type2  Value
2019-06-23 18:00:00        A       1     100
2019-06-23 18:00:00        B       1     106
2019-06-23 18:00:00        A       2     68
2019-06-23 18:00:00        B       2     156
2019-06-23 19:00:00        A       1     60
2019-06-23 19:00:00        B       1     326
2019-06-23 19:00:00        A       2     648
2019-06-23 19:00:00        B       2     3556

dt2:

     Date                Type1   Type2  Value_forecast
2019-06-23 18:00:00        A       1     67868
2019-06-23 18:00:00        B       1     876
2019-06-23 18:00:00        C       2     76
2019-06-23 18:00:00        B       2     856
2019-06-23 20:00:00        A       1     60
2019-06-23 20:00:00        B       1     326
2019-06-23 20:00:00        A       2     648
2019-06-23 20:00:00        B       2     3556

我想通过三列将它们连接起来:Date,Type1和Type2,并仅保留匹配的那些行。草皮的理想结果是:

     Date                Type1   Type2  Value    Value_forecast
2019-06-23 18:00:00        A       1     100         67868
2019-06-23 18:00:00        B       1     106          876
2019-06-23 18:00:00        B       2     156          856

我该怎么做?这个问题How to join (merge) data frames (inner, outer, left, right)与我的问题无关,因为我具有特定的结构,这使得加入变得更加复杂

0 个答案:

没有答案
相关问题