Calculate percentage for a column with certain condition of rows : <p>I have a following dataframe:</p>

<pre><code> sleep health count prop
1     7   Good   100   NA
2     7 Normal    75   NA
3     7    Bad    25   NA
4     8   Good   125   NA
5     8 Normal    75   NA
6     8    Bad    25   NA
</code></pre>

<p>I want to fill the <code>prop</code> column with each percentage of <code>count</code> based on <code>sleep</code> group. For instance, the first 3 rows <code>prop</code> should be 0.5, 0.375, and 0.125 then the last 3 rows <code>prop</code> are 0.555, 0.333, and 0.111 respectively.</p>

<p>This can be done manually by separating the data frame by <code>sleep</code> first then use <code>prop.table(prop)</code> for each, but since there are numerous <code>sleep</code> group I can't find a succinct way to do this. Any thoughts?</p>
