Reputation: 597
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
Upvotes: 0
Views: 1797
Reputation: 7475
exclude<-!(paste(df2$primer,df2$replicate,sep='~')%in%paste(df1$primer,df1$replicate,sep='~'))
df2[exclude,]
# primer exptname concentrate timepoints replicate day realConc
#1 Acan 0hr 55mM 0 b1 11311 0.0002771494
#2 Acan 0hr 55mM 20 b1 11311 0.0061298654
#3 Acan 0hr 55mM 40 b1 11311 0.0015750373
if you dont like to use paste you could also use
exclude<-!((df2$primer%in%df1$primer)&(df2$replicate%in%df1$replicate))
Upvotes: 2