title: Calculate the percent occurrence of a variable in multiple groups
body: <p>Sample data</p>
  
  <pre><code>set.seed(123)
  df &lt;- data.frame(loc.id = rep(1:1000, each = 35), year = rep(1980:2014,times = 1000),month.id = sample(c(1:4,8:10,12),35*1000,replace = T))
  </code></pre>
  
  <p>The data frame has a 1000 locations X 35 years of data for a variable called <code>month.id</code> which is basically the month of a year. For each  year, I want to calculate percent occurrence of each month. For e.g. for 1980, </p>
  
  <pre><code>month.vec &lt;- df[df$year == 1980,]
  table(month.vec$month.id)
  1   2   3   4   8   9  10  12 
  106 132 116 122 114 130 141 139 
  </code></pre>
  
  <p>To calculate the percent occurrence of months:</p>
  
  <pre><code>table(month.vec$month.id)/length(month.vec$month.id) * 100
  1    2    3    4    8    9   10   12 
  10.6 13.2 11.6 12.2 11.4 13.0 14.1 13.9 
  </code></pre>
  
  <p>I want to have a table something like this: </p>
  
  <pre><code>    year month percent
      1980   1    10.6
      1980   2    13.2
      1980   3    11.6
      1980   4    12.2
      1980   5    NA
      1980   6    NA
      1980   7    NA
      1980   8    11.4    
      1980   9    13
      1980   10   14.1
      1980   11   NA
      1980   12   13.9
  </code></pre>
  
  <p>Since, months 5,6,7,11 are missing, I just want to add the additional rows with NAs for those months. If possible, I would
  like a dplyr solution to something like this:</p>
  
  <pre><code>   library(dplyr)
     df %&gt;% group_by(year) %&gt;% summarise(percentage.contri = table(month.id)/length(month.id)*100)  
  </code></pre>