Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 473

Remove 'duplicate' rows based on combinations in two columns

$
0
0

I have this example data.frame:

df1 <- data.frame(v1 = c('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'),                  v2 = c('B', 'A', 'D', 'C', 'F', 'E', 'H', 'G'),                  value = c(1.12, 1.12, 12.52, 12.52, 3.19, 3.19, 12.52, 12.52))> df1  v1 v2 value1  A  B  1.122  B  A  1.123  C  D 12.524  D  C 12.525  E  F  3.196  F  E  3.197  G  H 12.528  H  G 12.52

Combinations such as A and B in row 1 are the same to me as combinations such as B and A, where values in column value are also the same. How can I remove rows which for my purpose are duplicates?

Expected result:

df2 <- data.frame(v1 = c('A', 'C', 'E', 'G'),                  v2 = c('B', 'D', 'F', 'H'),                  value = c(1.12, 12.52, 3.19, 12.52))> df2  v1 v2 value1  A  B  1.122  C  D 12.523  E  F  3.194  G  H 12.52

Viewing all articles
Browse latest Browse all 473

Trending Articles