Subsetting a data.table using another data.table

前端 未结 2 842
情书的邮戳
情书的邮戳 2021-01-06 11:43

I have the dt and dt1 data.tables.

dt<-data.table(id=c(rep(2, 3), rep(4, 2)), year=c(2005:2007, 2005:2006), event=         


        
2条回答
  •  独厮守ぢ
    2021-01-06 12:13

    setkeyv(dt,c('id','year'))
    setkeyv(dt1,c('id','year'))
    dt[dt1,nomatch=0]
    

    Output -

    > dt[dt1,nomatch=0]
       id year event performance
    1:  2 2005     1        1000
    2:  2 2006     0        1001
    3:  2 2007     0        1002
    

提交回复
热议问题