title: Applying a function to every combination of rows in a matrix using R | common connections
body: <p>I am new in R and I want to calculate the common and unique- connections of the components (CM) for my matrix.</p>
  <p>Therefore, I have a matrix of Components(CM) and Workstations(WS).
  To calculate the common connection, I want to find out which component is produced by which workstation(as shown in the matrix) in comparison to the other components.
  Common connections = when CM1 and CM2 are produced by the same workstation
  unique connection = when CM1 is produced by the workstation and CM2 not.</p>
  <pre><code>Example
       WS1 WS2 WS3 WS4 WS5 WS6 WS7 WS8 WS9 WS10
  CM1    1   0   1   1   1   1   1   1   0    0
  CM2    0   1   0   0   0   1   1   1   0    0
  CM3    1   0   0   1   1   0   1   0   0    1
  CM4    0   1   1   1   1   0   1   1   1    1
  CM5    1   0   0   1   0   0   0   1   0    1
  CM6    0   1   0   1   0   0   0   0   1    0
  CM7    0   1   1   1   1   1   1   0   1    1
  CM8    1   0   0   1   1   1   1   1   1    0
  CM9    1   0   0   1   1   1   0   1   1    0
  CM10   1   1   0   0   1   0   0   1   0    0
  </code></pre>
  <p>I need a function, which compares each element of a row (for instance : CM1) with another row(for instance : CM2). For instance if CM1[6] &amp; CM2[6] &gt;= 1 the sum is to be formed. For example the common connection of CM1_2 would be 3. Additionally, I also need this for the uncommon connections, whereas CM1[1] &gt;0 &amp; CM[2] == 0.</p>
  <p>For vectors, it should work like this:</p>
  <pre><code>a = CM1 #as a vector
  b = Cm2 #as a vector
  common &lt;- sum(a&amp;b &gt;=1)  #common connection
  only_inCM1 &lt;- sum(a &gt;0 &amp; b ==0) #unique connections
  only_inCM2 &lt;- sum(b &gt;0 &amp; a ==0)
  </code></pre>
  <p>My current Problem is to create all the combinations of the common and uncommon connections. So the function needs to compare CM1 with CM2, CM1 with CM3...until CM10 with CM9, calculating the common connection and the unique connections and afterwards for each comparison (like. CM1_2) it should apply the function C[n] on top.</p>
  <p>C[n] = 100 * common_connection/ common_connection +unique connection</p>
  <p>In the end, I want to calculate the sum of C[n] for all components divided by the number of Components. To have a general Index.</p>
  <hr />
  <p>example for CM1 and CM2</p>
  <pre><code>     WS1 WS2 WS3 WS4 WS5 WS6 WS7 WS8 WS9 WS10
  CM1    1   0   1   1   1   1   1   1   0    0
  CM2    0   1   0   0   0   1   1   1   0    0
  
  common connection CM1_2 = 3
  only in CM1 = 4
  only in CM2 = 1
  C[1,2] = 100 * 3 / 3+4 = 42,85  # Index for CM1 
  C[2,1] = 100* 3 / 3+1  = 75  # Index for CM2
  
  C = (C[1,2] + C[2,1]) / 2 = (42,85 + 75)/2 = 58,87
  
  </code></pre>
  <p>I hope you have an advice or an hint help me, many thanks in advance :)</p>