I have a data.frame with three columns FROM, TO (direction from, direction to) and COUNT:
FROM, TO, COUNT
A, B, 3
B, A, 4
C, D, 1
X, Y, 6
D, C, 9
I need to group by rows and sum the COUNT, if I have a opposite direction present in the data.frame.
Expected result:
FROM, TO, COUNT
A, B, 7 <------- (A, B) 3 + 4 (B,A)
C, D, 10 <- (C, D) 1 + 9 (D,C)
X, Y, 6 <- stays as there is no opposite Y to X