Recently, I wanted to count the number of occurence of a relationship between 2 variables whatever the order of the relation is. In other words,
Variable1 Variable2
A B
B A
I should get
Variable1 Variable2 Weight
A B 2
I could tried something like
result <- aggregate(var_to_sum, by=list(var1,var2), FUN=sum, na.rm=TRUE)
However I dont know how to make A B equals to B A
Author1 <- ifelse(var1>var2,var1,var2)
But it does not work, any idea how to solve this problem?