What does < stand for in data.table joins with on=

后端 未结 2 1756
走了就别回头了
走了就别回头了 2020-12-06 18:11

Joining the data tables:

X <- data.table(A = 1:4, B = c(1,1,1,1)) 
#    A B
# 1: 1 1
# 2: 2 1
# 3: 3 1
# 4: 4 1

Y <- data.table(A = 4)
#    A
# 1: 4
<         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 19:00

    When doing a non-equi join like X[Y, on = .(A < A)] data.table returns the A-column from Y (the i-data.table).

    To get the desired result, you could do:

    X[Y, on = .(A < A), .(A = x.A, B)]
    

    which gives:

       A B
    1: 1 1
    2: 2 1
    3: 3 1
    

    In the next release, data.table will return both A columns. See here for the discussion.

提交回复
热议问题