title: Divide row value by aggregated sum in R data.frame
body: <p>I have the following data frame</p>
  
  <pre><code>dat &lt;- data.frame(x=c(1,2,3,3,2,1), y=c(3,4,4,5,2,5))
  </code></pre>
  
  <p>Now I would like to get a third column dividing the y row value by the aggregated y values (based on the unique values in column x). So, then I get row 1 as following: 1,3,0.375; 0.375 has been calculated as 3 / (5+3). </p>
  
  <p>I'm relatively new to R and I hope you can help me. Thank you!</p>