title: Using proportion as the aggregate function in Data.Table's dcast
body: <p>When creating a pivot table using data.table, I am using the dcast function:</p>
  
  <pre><code>dcast(my_data, var1 ~ var2, length)
  </code></pre>
  
  <p>This gives a table with rows as var1 lables and column as var2 labels and value as count of cells common to particular row and column.</p>
  
  <p>But instead of length I want to calculate the proportion and put it as the value, i.e. {count of cells common to particular row and column} divided by {count of all cells in the column i.e. a particular level of var2}</p>
  
  <p>I have searched and couldn't able to implement it.
  Any help would be appreciated.</p>