title: R: Merging dataframe where index of multiple columns is an unordered set
body: <p>I have a list of countries</p>
  
  <pre><code>countries &lt;- c("MAL","CHL","URU","YPR","OMA","GUY","HON","SAL","CYP")
  </code></pre>
  
  <p>and two dataframes containing all possible dyads among the two countries</p>
  
  <pre><code>set.seed(28100)
  df1 &lt;- as.data.frame(t(combn(countries, 2)))
  df1$year &lt;- sample(1800:2000, 36)
  df1$value1 &lt;- sample(1:100, 36)
  
  df2 &lt;- as.data.frame(t(combn(rev(countries), 2)))
  df2$year &lt;- sample(1800:2000, 36)
  df2$value2 &lt;- sample(LETTERS, 36, replace = TRUE)
  </code></pre>
  
  <p>Now I want to merge the two dataframes by countries and by year (<code>by = c("V1","V2","year")</code>) without worrying about the actual order in which the pair of countries is listed. 
  So the observation where <code>V1 == "SAL"</code> and <code>V2=="CYP"</code> can either merge with <code>V1 == "SAL"</code> and <code>V2=="CYP"</code> or <code>V2 == "SAL"</code> and <code>V1=="CYP"</code>.</p>