2013-08-01 41 views
-3

我有两个数据帧,df1df2用R中的多个键删除行

DF1:

contig position tumor_f t_ref_count t_alt_count 
1  14599 0.000000   1   0 
1  14653 0.400000   3   2 
1  14907 0.333333   6   3 
1  14930 0.363636   7   4 

DF2:

contig position 
1  14599 
1  14653 

我想从DF1具有匹配重叠群,在DF2位置值删除的行。

+0

为什么这个问题downvoted? – Aert

+0

@Aert可能是因为OP简单地阐述了他的要求。 Stackoverflow不喜欢*你能给我codez *类型的问题。如果OP已经尝试了一些东西,并在此发布结果,那么这个问题本可以是好的。 – Krishnabhadra

+0

发表一些代码。 –

回答

1

这是一种方法。我相信还有其他的解决方案,

conpos_del <- with(df2, interaction(contig,position,drop=T)) 
subset(df1, !interaction(contig,position,drop=T) %in% conpos_del) 
+0

也许在形成'conpos_del'的交互周围使用unique()? –

+0

你可以,但%在%中没有区别! –

0

您可以使用match()功能与负面子集:

df1 <- data.frame(contig = c(1,1,1,1), position = c(14599, 14653, 
    14907, 14930), other = c(1,2,6,7)) 

df2 <- data.frame(contig = c(1,1), position = c(14599, 14653)) 

df1[-na.omit(match(df1$position, df2$position)), ] 
1

这不是很漂亮,但它的工作原理

df1[!paste(df1$contig, df1$position) %in% paste(df2$contig, df2$position),] 
0
df1[ ! with(df1, interaction(contig, position) %in% 
        with(df2, unique(interaction(contig , position))) , ]