Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete duplicate rows in two columns simultaneously [duplicate]

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!

like image 228
user3091668 Avatar asked Aug 14 '14 06:08

user3091668


Video Answer


1 Answers

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")]),]
like image 133
akrun Avatar answered Oct 22 '22 07:10

akrun