title: using the table function in a loop
body: <p>I'm trying to get the table() function to run in a for loop, Ideally I would put the output into a dataframe, however I'm not getting below to work, any ideas?</p>
  
  <pre><code>for(i in unique(ModuleMarks$Module)){
       table(i[,6])
  }
  </code></pre>
  
  <p>Table structure </p>
  
  <pre><code>   Module  Out of Mark  Mark percentage Judgment JudgmentChar
     &lt;chr&gt;         &lt;dbl&gt; &lt;dbl&gt;      &lt;chr&gt;    &lt;dbl&gt;        &lt;chr&gt;
  1 LW1001            NA    NA       &lt;NA&gt;       NA         test
  2 LW1001            NA    NA       &lt;NA&gt;       NA         test
  3 LW1001            NA    NA       &lt;NA&gt;       NA         test
  4 LW1001            NA    NA       &lt;NA&gt;       NA         test
  .
  .
  .
  1 LW6627           100    57         57       57          2.2
  2 LW6627           100    63         63       63          2.1
  3 LW6627           100    62         62       62          2.1
  4 LW6627           100    65         65       65          2.1
  5 LW6627           100    67         67       67          2.1
  6 LW6627           100    64         64       64          2.1
  This goes on for 7000+rows
  </code></pre>
  
  <p>So I'm trying to go though each module code and get the table for each module, which their could be 1 to 500.</p>
  
  <p>The example output would be</p>
  
  <pre><code>table(LW1108[,6])
  1h  2.1  2.2  3.1 Fail Pass test 
  54  196  122   21   23   15    7 
  </code></pre>
  
  <p>but for each Module</p>
  
  <pre><code>table(LW1108[,6])
  Module 1h  2.1  2.2  3.1 Fail Pass test 
  LW1101 54  196  122   21   23   15    7 
  LW1102 54  196  122   21   23   15    7 
  .
  .
  .
  LW6601 54  196  122   21   23   15    7 
  </code></pre>
  
  <p>The nub of the problem is that it is not passing i through the table function.</p>
  
  <p>Thanks</p>