0

I have a data.frame with the specific format:

df <- structure(list(Left.align = c("A", "B", "C", "F"), Right.align = c("B", 
"A", "D", "E"), Center.align = c(2, 2, 3, 6)), .Names = c("Left.align", 
"Right.align", "Center.align"), row.names = c(NA, -4L), class = "data.frame")

df
  Left.align Right.align Center.align
1          A           B            2
2          B           A            2
3          C           D            3
4          F           E            6

I would to remove B A 2, because the result is the same that A B 2. How will I do this in R?

thanks!

www
  • 38,575
  • 12
  • 48
  • 84

1 Answers1

1

We can sort by row and then use duplicated to get a logical index to subset the rows of dataset

df1[!duplicated(t(apply(df1, 1, sort))),]
akrun
  • 874,273
  • 37
  • 540
  • 662