2013-08-01 42 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))) , ]