Complexe non-equi merge in R

后端 未结 2 2073
一向
一向 2020-12-01 09:44

I\'m trying to do a complexe non-equi join between two tables. I got inspired by a presentation in the last useR2016 (https://channel9.msdn.com/events/useR-international-R-

2条回答
  •  甜味超标
    2020-12-01 10:32

    So I was very close. I had 2 problems, first a bad installation of the data.table package (Data table error could not find function ".") caused an obscure error.

    After having fixed that, I got closer an found that :

    dt1[dt2, on=.(sp=sp, dbh>=dbh_min, dbh<=dbh_max), nomatch=0]
    

    gave me what I wanted with a bad dbh column. Inverting the command with:

    dt2[dt1, on=.(sp=sp, dbh_min<=dbh, dbh_max>=dbh)]
    

    fixed the problem with only one useless extra column.

提交回复
热议问题