Say I have some network data as shown below:
col_a <- c("A","B","C")
col_b <- c("B","A","A")
val <- c(1,3,7)
df <- data.frame(col_a, col_b, val)
df
col_a col_b val
1 A B 1
2 B A 3
3 C A 7
This could be a network and val could be the weight of the edges between the two. However, I want to add the weight between A and B and B and A to get the following:
new_col_a <- c("A", "A")
new_col_b <- c("B", "C")
new_val <- c(4,7)
want_df <- data.frame(new_col_a, new_col_b, new_val)
want_df
new_col_a new_col_b new_val
1 A B 4
2 A C 7
Is there a way to do this in dplyr
?