When creating a pivot table using data.table, I am using the dcast function:
dcast(my_data, var1 ~ var2, length)
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.
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}
I have searched and couldn't able to implement it. Any help would be appreciated.