title: How can I identify and count unique pairs at every level in a list of lists in R?
body: <p>I have a list of lists that looks like this:</p>
  
  <pre><code>&gt; class(cladelist)
  [1] "list"
  
  cladelist &lt;- list( `46` = scan(text=' "KbFk2"  "PeHa3"  "PeHa51" "EeBi27" "EeBi17" "PeHa23" "PeHa44" "EeBi4"  "EeBi26" "PeHa8"  "PeHa26" "EeBi24" "EeBi3" 
   "EeBi20" "KbFk5"  "PeHa15" "PeHa43" "PeHa11" "PeHa12" "PeHa49" "PeHa67" "PeHa17" "PeHa59" "KbFk4"  "PeHa10" "PeHa55"
   "PeHa73" "EeBi23" "PeHa78" "PeHa81" "EeBi11" "PeHa45" "EeBi6"  "EeBi34" "PeHa25" "PeHa52" "PeHa62" "PeHa31" "PeHa65"
   "PeHa47" "PeHa50" "PeHa34" "PeHa54" "PeHa22" "PeHa30"', what=""),
  
  `47`= scan(text='
   "KbFk2"  "EeBi27" "EeBi17" "EeBi4"  "EeBi26" "EeBi3"  "EeBi20" "KbFk5"  "KbFk4"  "EeBi6"  "EeBi34"', what=""),
  
  `48`= scan(text=' "PeHa3"  "PeHa51" "PeHa23" "PeHa44" "PeHa8"  "PeHa26" "EeBi24" "PeHa15" "PeHa43" "PeHa11" "PeHa12" "PeHa49" "PeHa67"
   "PeHa17" "PeHa59" "PeHa10" "PeHa55" "PeHa73" "EeBi23" "PeHa78" "PeHa81" "EeBi11" "PeHa45" "PeHa25" "PeHa52" "PeHa62"
   "PeHa31" "PeHa65" "PeHa47" "PeHa50" "PeHa34" "PeHa54" "PeHa22" "PeHa30"', what=""),
  
  `49`= scan(text=' "PeHa51" "PeHa23" "PeHa44" "PeHa8"  "PeHa26" "EeBi24" "PeHa15" "PeHa43" "PeHa11" "PeHa12" "PeHa49" "PeHa67" "PeHa17"
   "PeHa59" "PeHa10" "PeHa55" "PeHa73" "EeBi23" "PeHa78" "PeHa81" "EeBi11" "PeHa45" "PeHa25" "PeHa52" "PeHa62" "PeHa31"
   "PeHa65" "PeHa47" "PeHa50" "PeHa34" "PeHa54" "PeHa22" "PeHa30"', what=""),
  
  `50`= scan(text=' "EeBi27" "EeBi17" "EeBi4"  "EeBi26" "EeBi3"  "EeBi20" "KbFk5"  "KbFk4"  "EeBi6"  "EeBi34"', what="") )
  </code></pre>
  
  <p>Each of these sublists (ie "46", "47" etc) represents a clade in a dendogram that I've extracted using:</p>
  
  <pre><code>&gt; cladelist &lt;- clade.members.list(VB.phy, tips = FALSE, tip.labels = TRUE, include.nodes=FALSE)
  </code></pre>
  
  <p>Im trying to find each unique pair found within each sublist, and calculate the sum of times it appears between all sublists (clades). </p>
  
  <p>The ideal output would be a dataframe that looks like this where the count is the number of times this pair was found between all sublists (clades):</p>
  
  <pre><code>Pair     Count
  Peha1/PeHa2 2
  Peha1/PeHa3 4
  PeHa1/PeHa4 7
  PeHa1/PeHa5 3
  </code></pre>
  
  <p>What sort of formulas am I looking for?</p>
  
  <p>Background for the question (just for interest, doesnt add that much to question): </p>
  
  <p>The idea is that I have a data set of 121 of these elements (Peha1, KbFk3, etc). They are artifacts (I'm an archaeologist) that I'm evaluating using 3D geometric morphometrics. The problem is that these artifacts are not all complete; they are damaged or degraded and thus provide an inconsistent amount of data. So I've had to reduce what data I use per artifact to have a reasonable, yet still inconsistent, sample size. By selecting certain variables to evaluate, I can get useful information, but it requires that I test every combination of variables. One of my analyses gives me the dendograms using divisive hierarchical clustering. <a href="https://i.stack.imgur.com/AyLlJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AyLlJ.png" alt="enter image description here"></a></p>
  
  <p>Counting the frequency of each pair as found between each clade should be the strength of the relationship of each pair of artifacts. That count I will then divide by total number of clades in order to standardize for the following step. Once I've done this for X number of dendograms, I will combine all these values for each pair, and divide them by the number representing whether that pair appeared in a dendogram (if it shows up in 2 dendograms, that I divide by 2), because each pair will not appear in each of my tests and I have to standardize it so that more complete artifacts that appear more often in my tests don't have too much more weight. This should allow me to evaluate which pairs have the strongest relationships. </p>