Let DT be a 4 x 2 data table with two columns, X and Y, and the following values:
X|Y
---
1 2
2 1
3 4
4 3
I want to remove duplicated pairs from the data table, namely row 2 and 4 in DT.
Let DT be a 4 x 2 data table with two columns, X and Y, and the following values:
X|Y
---
1 2
2 1
3 4
4 3
I want to remove duplicated pairs from the data table, namely row 2 and 4 in DT.
One option could be:
df[!duplicated(paste0(pmax(X, Y), pmin(X, Y))), ]
X Y
1: 1 2
2: 3 4
The same with dplyr:
df %>%
group_by(ID = paste0(pmax(X, Y), pmin(X, Y))) %>%
slice(1)
Or with base R:
df[!duplicated(with(df, paste0(pmax(X, Y), pmin(X, Y)))), ]