同时删除两列中的重复行

同时删除两列中的重复行

本文介绍了同时删除两列中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我输入 df 我想删除重复的行, :

  RAW.PVAL GR allrl Bak 
0.05 fr EN1 B12
0.05 fg EN1 B11
0.45 fr EN2 B10
0.35 fg EN2 B066

我的输出:

  RAW.PVAL GR allrl Bak 
0.05 fr EN1 B12
0.45 fg EN2 B10
0.35 fg EN2 B066

我尝试过 df< - subset(df,!duplicated(allrl,RAW .PVAL)),但是我不会删除这两列同时重复的行。



谢谢!

解决方案

如果您想使用子集,您可以尝试:

$ b (df,!duplicateated(subset(df,select = c(allrl,RAW.PVAL))))
#RAW.PVAL GR allrl Bak
#1 0.05 fr EN1 B12
#3 0.45 fr EN2 B10
#4 0.35 fg EN2 B066

但是,我认为@ thelatemail的方法会更好

  df [!duplicateated(df [c(RAW.PVAL,allrl)])] 


I would like to delete duplicate rows based in two collumns, instead just one.

My input df:

RAW.PVAL  GR     allrl  Bak
0.05      fr     EN1    B12
0.05      fg     EN1    B11
0.45      fr     EN2    B10
0.35      fg     EN2    B066

My output:

RAW.PVAL  GR  allrl   Bak
0.05      fr   EN1    B12
0.45      fg   EN2    B10
0.35      fg   EN2    B066

I had tried df<- subset(df, !duplicated(allrl, RAW.PVAL)), but I do not work to delete rows with this two columns simultaneously duplicated.

Thank you!

解决方案

If you want to use subset, you could try:

  subset(df, !duplicated(subset(df, select=c(allrl, RAW.PVAL))))
 # RAW.PVAL GR allrl  Bak
 #1     0.05 fr   EN1  B12
 #3     0.45 fr   EN2  B10
 #4     0.35 fg   EN2 B066

But, I think @thelatemail's approach would be better

  df[!duplicated(df[c("RAW.PVAL","allrl")]),]

这篇关于同时删除两列中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 03:06