Imagine I have a data frame that looks like this:
df <- data.frame(
name1 = c("John", "Jake", "Ann", "Mary", "Harry"),
name2 = c("Jake", "John", "Mary", "Ann", "Mary"),
value = c(2, 4, 6, 8, 10)
)
I want to create a new data frame that sums value over any rows where name1 and name2 and the same regardless of their order. So my result would be:
result <- data.frame(
name1 = c("John", "Ann", "Harry"),
name2 = c("Jake", "Mary", "Mary"),
value = c(6, 14, 10)
)
Any clever ideas, preferably using tidyverse? Thanks so much!