Вот еще один вариант, основанный на ваших данных
library(tidyverse)
## data
m <- expand.grid(LETTERS[1:24],LETTERS[1:24],
stringsAsFactors = FALSE) # you should use stringsAsFactors = FALSE
m$weight <- runif(nrow(m), 0.01, max = 1)
#m <- m[m$Var1 != m$Var2, ] ##remove loop edges
m <- filter(m, Var1 != Var2) # filter also does the job
colnames(m) = c("to","from","weight")
## result
m <- m %>%
arrange(to) %>%
mutate(edge = ifelse(to < from, paste(to, from, sep = ","),
paste(from, to, sep = ","))) %>%
group_by(edge) %>%
mutate(final_weight = abs(weight[1] - weight[2])) %>%
select(edge, final_weight) %>%
distinct() %>%
separate(edge, c("to", "from"), ",")