Skip to Content

excluding rows in a data frame which matches multiple column values in another data frame

df1

   day  primer replicate count
011311     Arc        b1     0
011311    Bdnf        b1     0
011311    Bves        b1     0
011311     Crh        b1     0
011311    Egr1        b1     0

I have the following df1, and want to exclude rows in df2 which are equal to the df1's primer and replicate values.

df2

primer exptname concentrate timepoints replicate  day     realConc
Acan      0hr        55mM          0        b1 011311 0.0002771494
Acan      0hr        55mM         20        b1 011311 0.0061298654
Acan      0hr        55mM         40        b1 011311 0.0015750373
Arc       0hr        55mM          0        b1 011311 0.0010109867
Arc       0hr        55mM         20        b1 011311 0.0035939088
Arc       0hr        55mM         40        b1 011311 0.0133760938

So I guess my question is that I don't know how to do a 2 way match. And then exclude those values (in this case rows)

I want this

new_df

primer exptname concentrate timepoints replicate  day     realConc
Acan      0hr        55mM          0        b1 011311 0.0002771494
Acan      0hr        55mM         20        b1 011311 0.0061298654
Acan      0hr        55mM         40        b1 011311 0.0015750373

I was thinking something like:

new_df <- df2[!which(match(paste(df2$primer,df$replicate),paste(df1$primer,df$replicate))),]

obviously not working though