title: Frequency of combined factors and their inverse
body: <p>I would like to calculate the frequency of pairs.</p>
  
  <p>The dataframe has 2 columns of multiple factors variables like this:</p>
  
  <pre><code>    df
       A1 A2  
       1 "A" "A"
       2 "D" "C"
       3 "B" "A"
       4 "D" "C"
       5 "D" "C"
       6 "A" "B"
       7 "B" "A"
       8 "C" "D"
  </code></pre>
  
  <p>My data frame has hundreds of lines and 20 variables.</p>
  
  <p>I have tried with the count function from plyr:</p>
  
  <pre><code>    count(df, c("A1", "A2"))
       A1 A2 freq
       1    A  A    1
       2    A  B    1
       3    B  A    2
       4    C  D    1
       5    D  C    3
  </code></pre>
  
  <p>But my goal is to have a result that looks like this:</p>
  
  <pre><code>     A1 A2 freq
       1    A  A    1
       2    A  B    3
       3    C  D    4
  </code></pre>