Subsetting a data frame to the rows not appearing in another data frame

后端 未结 5 891
温柔的废话
温柔的废话 2021-01-23 13:53

I have a data frame A with observations

    Var1   Var2  Var3
     1       3    4
     2       5    6
     4       5    7
     4       5    8
     6       7    9         


        
5条回答
  •  迷失自我
    2021-01-23 14:39

    Using data.table you could do an anti-join as follows:

    library(data.table)
    setDT(df1)[!df2, on = names(df1)]
    

    which gives the desired result:

       Var1 Var2 Var3
    1:    4    5    7
    2:    4    5    8
    3:    6    7    9
    

提交回复
热议问题