I have a dataframe with two columns that repeat themselves in reverse order (i.e. the pairing of the two columns will always be the same)
Example:
col1 <- c('a', 'c', 'g', 'd', 'e', 'b', 'f', 'h')
col2 <- c('b', 'd', 'h', 'c', 'f', 'a', 'e', 'g')
df <- data.frame(col1, col2, stringsAsFactors = FALSE)
I want to add a column as an identifier of these combinations regardless of the order (e.g. row 1 and row 6 are equivalent). The final solution would look like:
col1 col2 ID
1 a b 1
2 c d 2
3 g h 3
4 d c 2
5 e f 4
6 b a 1
7 f e 4
8 h g 3