Question

Imagine I have a data frame with data like this:

 A | B | C
---+---+---
 1 | 2 | a
 1 | 2 | b
 5 | 5 | a
 5 | 5 | b

I want to take only columns A and B, and I want to remove any rows that have become duplicates as a result of eliminating all other columns (that is, column C). So my desied result for the table above would be:

 A | B
---+---
 1 | 2 
 5 | 5 

What is the best way to do this?

Was it helpful?

Solution

If your data.frame is called df, then do this:

unique(df[, c("A", "B")])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top