title: Calculate the percentages of a column in a data frame - "grouped" by column
body: <p>I am an R beginner and came to the point, where I need the possibility to calculate percentages of values in a data frame, but "grouped" by an other column value, quite often.</p>
  
  <p>I have a data frame with around 1000 rows, containing mediatype, version, collection (= year) and count (for this year). I can filter them, to get only a specific mediatye:</p>
  
  <pre><code>trSpdf &lt;- trS[trS$Mediatype == 'application/pdf',]
  </code></pre>
  
  <p>and get the following exemplary output:</p>
  
  <pre><code>&gt; trSpdf 
  
          Mediatype Version Collection      Count
  39 application/pdf      -1     co2008         2.0
  40 application/pdf      -1     co2009         5.0
  43 application/pdf       1     co2008         1.0
  44 application/pdf       1     co2009         1.0
  48 application/pdf     1.1     co2008        16.0
  52 application/pdf     1.2     co2008        20.0
  53 application/pdf     1.2     co2009        90.0
  ... (continuing) ...
  </code></pre>
  
  <p>What I want, is to calculate the percentage of each version for each collection (= year) compared to all versions in this collection, so for this example the result should be:</p>
  
  <pre><code>5.12% of all versions in co2008 were version -1 (2.0 / total sum for co2008)
  2.56% of all versions in co2008 were version 1 (1.0 / total sum for co2008)
  ...
  93,75% of all versions in co2009 were version 1.2 (90.0 / total sum for co2009)
  ...
  </code></pre>
  
  <p>Thanks in advance for any answers on how I could solve this.</p>