我有两个看起来像这样的数据框:
DF1:
public Object pop() throws EmptyStackException {
if (isEmpty())
throw new EmptyStackException();
this.size--;
Object result = this.elements[size];
this.elements[size] = null;
if (size < (capacity / 4)) {
capacity = capacity / 2;
Object temp[] = elements;
elements = new Object[capacity];
for (int i = 0; i < temp.length; i++)
elements[i] = temp[i];
}
return result;
}
和df2:
V1 V2 V3 V4
rs200140498 chr1 861315 GG
rs371217242 chr1 861329 AA
rs200686669 chr1 861349 CC
rs370046315 chr1 861357 CC
rs374110379 chr1 861521 GG
rs74045401 chr1 861530 GG
rs377418023 chr1 865394 CC
rs79027658 chr1 865438 CC
rs202189913 chr1 865488 AA
rs370992396 chr1 865543 GG
我想比较它并获得新数据框:
V1 V2 V3 V4
rs200140498 chr1 861315 GG
rs200686669 chr1 861349 CC
rs370046315 chr1 861357 CC
rs74045401 chr1 861530 GG
rs377418023 chr1 865394 CC
rs202189913 chr1 865488 AA
rs370992396 chr1 865543 GG
任何人都可以帮我吗?
答案 0 :(得分:1)
尝试一下:
library(dplyr) #you need to install and load the dplyr package
df3 <- left_join(df1,df2, by=c("V1", "V2", "V3"))
df3 <- df3[,-4]
View(df3)
此外,如果您只需要差异,那么我建议使用anti_join
功能:
df4 <- anti_join(df1,df2, by=c("V1", "V2", "V3"))
View(df4)
如果您需要--
而不是NA
值,请使用以下内容:
df3$V4.y <- replace(df3$V4.y, is.na(df3$V4.y), "--")