Inner join using an inequality expression

前端 未结 2 467
猫巷女王i
猫巷女王i 2020-12-31 18:22

Background

(Not required for the question, but may be useful to read)

Rolling join on data.table with duplicate keys

Odd behaviour w

2条回答
  •  一向
    一向 (楼主)
    2020-12-31 19:16

    Here's the unclever approach: take the cross/Cartesian join, and then filter.

    merge(dt_arrive, dt_depart, allow.cartesian=TRUE)[arrival_minutes.y > arrival_minutes.x]
    
    #    txn_id   place arrival_minutes.x journey_id.x arrival_minutes.y journey_id.y
    # 1:      1 place_a               515            1               519           12
    # 2:      1 place_a               515            1               543           13
    # 3:      1 place_a               534            2               543           13
    

    By taking the Cartesian join, we're liable to eat up a lot of memory.

提交回复
热议问题