title: data.table - group size relative to total number of rows
body: <p>I'm looking for a concise data.table solution for the following:</p>
  
  <p>I want to add a new column "ratio" that is the size of each group in relation to the total number of rows of the dataframe.</p>
  
  <p>We can do it as follows: Add a column "N" that is constant and contains the total number of rows. Then group by the variable "group" and divide the group size by the total size:</p>
  
  <pre><code>df = data.table(group=c(rep("a", 2), rep("b", 3)))
  df[, N:=.N][, ratio := .N/N, group][,N:=NULL]
  </code></pre>
  
  <p>with the desired outcome:</p>
  
  <pre><code>   group ratio
  1:   a   0.4
  2:   a   0.4
  3:   b   0.6
  4:   b   0.6
  5:   b   0.6
  </code></pre>
  
  <p>But is there a better way without adding/removing the dummy column?</p>