Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my implementation in <code>R</code>. The code doesn't execute the steps exactly in the way you specified them. I focused on your final matrix and assumed that this is the main result you're interested in.</p> <pre><code>test &lt;- matrix(c(18,12,15,0,13,0,14,0,12),ncol=3, nrow=3) rownames(test) &lt;- paste("Skill", 1:dim(test)[1], sep="") colnames(test) &lt;- paste("People", 1:dim(test)[2], sep="") test # Pairwise combinations comb.mat &lt;- combn(1:dim(test)[2], 2) pairwise.mat &lt;- data.frame(matrix(t(comb.mat), ncol=2)) pairwise.mat$max.score &lt;- 0 names(pairwise.mat) &lt;- c("Person1", "Person2", "Max.Score") for ( i in 1:dim(comb.mat)[2] ) { # Loop over the rows first.person &lt;- comb.mat[1,i] second.person &lt;- comb.mat[2,i] temp.mat &lt;- test[, c(first.person, second.person)] temp.mat[temp.mat == 0] &lt;- NA temp.rowSums &lt;- rowSums(temp.mat, na.rm=FALSE) temp.rowSums[is.na(temp.rowSums)] &lt;- 0 max.sum &lt;- max(temp.rowSums) previous.val &lt;- pairwise.mat$Max.Score[pairwise.mat$Person1 == first.person &amp; pairwise.mat$Person2 == second.person] pairwise.mat$Max.Score[pairwise.mat$Person1 == first.person &amp; pairwise.mat$Person2 == second.person] &lt;- max.sum*(max.sum &gt; previous.val) } pairwise.mat Person1 Person2 Max.Score 1 1 2 25 2 1 3 32 3 2 3 0 person.mat &lt;- matrix(NA, nrow=dim(test)[2], ncol=dim(test)[2]) rownames(person.mat) &lt;- colnames(person.mat) &lt;- paste("People", 1:dim(test)[2], sep="") diag(person.mat) &lt;- 0 person.mat[cbind(pairwise.mat[,1], pairwise.mat[,2])] &lt;- pairwise.mat$Max.Score person.mat[lower.tri(person.mat, diag=F)] &lt;- t(person.mat)[lower.tri(person.mat, diag=F)] person.mat People1 People2 People3 People1 0 25 32 People2 25 0 0 People3 32 0 0 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload