title: Multiple Wilcox Tests as a loop in R
body: <p>My dataset consists of</p>
  
  <pre><code>cb &lt;- data.frame(group = ("A", "B", "C", "D", "E"), 
        WC = runif(100, 0, 100), 
        Ana = runif(100, 0, 100), 
        Clo = runif(100, 0, 100))
  
  str(cb)
  data.frame: 66936 obs of 89 variables: 
  $group: Factor w/ 5 levels "A", "B", "C" ...
  $WC: int 19 28 35 92 10 23...
  $Ana: num 17.2 48 35.4 84.2
  $ Clo: num 37.2 12.1 45.4 38.9
  ....
  </code></pre>
  
  <p>Now I want to perform multiple Wilcox tests on the $group, so that it looks like this in the end:</p>
  
  <pre><code>commands: 
  wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "B"])
  wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "C"])
  wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "D"])
  wilcox.test(cb$WC[cb$group == "A"], cb$WC[cb$group == "E"])
  ....
  
  inserting the p-value:
  WC   A     B    C     D    E
  A    1     0.12 0.03  0.2  0.42
  B    0.12  1    0.1   0.07 0.1
  C    0.03  0.1  1     0.2  0.3
  D    0.2   0.07 0.2   1    0.1
  E    0.42  0.1  0.3   0.1  1
  
  Ana   A     B    C     D    E
  A    1      0.12  0.2  0.39  0.1
  B    0.12   1     0.1  0.07  0.1
  C    ...
  D
  E
  
  ...
  </code></pre>
  
  <p>I have a for loop of a prior question, <a href="https://stackoverflow.com/questions/38638910/multiple-one-sample-t-test-in-r">multiple t-tests</a>, but i struggle to adapt it to this task, because the Wilcox-Test is so different in design.
  Here is the for loop I used for the t-test:</p>
  
  <pre><code>res &lt;- matrix(NA, ncol=5, 
  dimnames=list(NULL, c("group", "col", "statistic", "estimate", "p.value")))
  
  gr &lt;- levels(cb$group)
  
  for(cl in 2:ncol(cb)){
      for(grp in gr){
          temp &lt;- cb[cb$group == grp, cl]
          res &lt;- rbind(res, c(grp, colnames(cb)[cl], 
              unlist(t.test(temp, mu = mean(cb[,cl]), alternative="two.sided"))[c(1, 5, 3)]))
      }
  }
  </code></pre>
  
  <p>Do you have an idea how to change this for loop to perform a wilcox test? </p>