title: Calculating the proportion per subgroup with data.table
body: <p>For the following simple dataset;</p>
  
  <pre><code>   row  country year
       1  NLD     2005
       2  NLD     2005       
       3  BLG     2006
       4  BLG     2005
       5  GER     2005
       6  NLD     2007
       7  NLD     2005
       8  NLD     2008
  </code></pre>
  
  <p>the following code:</p>
  
  <pre><code>df[, .N, by = list(country, year)][,prop := N/sum(N)]
  </code></pre>
  
  <p>gives the proportion of observations compared to the total of observations. What I want however is to measure the proportion for each country. How should I adapt this code to give me the correct proportions?</p>
  
  <p>Desired output:</p>
  
  <pre><code>   row  country year  prop
       1  NLD     2005   0.6
       2  NLD     2005   0.6    
       3  BLG     2006   0.5
       4  BLG     2005   0.5
       5  GER     2005   1
       6  NLD     2007   0.2
       7  NLD     2005   0.6  
       8  NLD     2008   0.2
  </code></pre>