title: Normalize values in a column to obtain overheads
body: <p>I have the following data frame:</p>
  
  <pre><code>df &lt;- data.frame(
        Target=rep(LETTERS[1:3],each=8),
        Prov=rep(letters[1:4],each=2),
        B=rep("5MB"),
        S=rep("1MB"),
        BUF=rep("8kB"),
        M=rep(c('g','p')),
        Thr.mean=1:24)
  </code></pre>
  
  <p>whose column <code>Thr.mean</code> I would like to normalize by the values where <code>Target=='C'</code> (I don't mind attaching a new column).</p>
  
  <p>To clarify, I would like to end up with:</p>
  
  <pre><code>Thr.mean &lt;- c(1/17,2/18,3/19,4/20,5/21,6/22,7/23,8/24,9/17,10/18,11/19,12/20,13/21,14/22,15/23,16/24,1,1,1,1,1,1,1,1)
  </code></pre>
  
  <p>Now, it may happen that there are rows in this data frame, where <code>Target!='C'</code>, and they have values in <code>S</code> or <code>B</code> that are not present in rows where <code>Target=='C'</code>, and for these I would also like to calculate the overhead. The most important column for matching is <code>M</code>, then <code>BUF</code>, <code>B</code>, and <code>S</code>.</p>
  
  <p>Any ideas how to do it? I could write several loops and ifs, but I'm looking for a more elegant solution.</p>