title: Multiply values across each column by weight in another data.frame in R
body: <p>I have two <code>data.frames</code>: <code>df</code> and <code>weights</code> (code below).</p>
  <p><code>df</code> looks like this:</p>
  <pre><code>    id             a           b           d           EE           f
   1  this           0.23421153  -0.02324956 0.5457353   0.73068586   0.5642554
   2  is             0.28378641  0.36346241  1.0190496   1.97715019   -1.190179
   3  an             -0.04372133  0.07412557  -0.4510299  1.8442713   -0.5301328
   4  example        -0.18139887  0.10404329  -1.0871962  1.46920108  0.4685703
   5  data.frame     0.24235498   -0.1501064  -1.1183967  0.22884407  0.4272259
   6  for             -0.72718239 0.16337997  1.2635683   0.44206945  0.7303647
   7  stackoverflow  0.25203942   -0.1772715  -0.3371532  -0.29167792 -0.7065494
   8  please         -0.11047364  -0.06631552 0.4342659   -1.49584522 0.2837016
   9  help           -0.1136639   0.22414253  0.4284864   1.59096047  0.2915938
   10 me             -0.3677288   0.05974474  -0.1136177  0.02322094  -0.6533994
  </code></pre>
  <p>How can I multiply the values in each of the columns by the corresponding weights in the <code>weights</code> <code>data.frame</code>?</p>
  <p>Expected result:</p>
  <pre><code>    id            a             b           d            EE   f
   1  this          0.749476896   -0.1743717  5.29363241   NA   4.17548996
   2  is            0.908116512   2.725968075 9.88478112   NA   -8.8073246
   3  an            -0.139908256  0.555941775 -4.37499003  NA   -3.92298272
   4  example       -0.580476384  0.780324675 -10.54580314 NA   3.46742022
   5  data.frame    0.775535936   -1.125798   -10.84844799 NA   3.16147166
   6  for           -2.326983648  1.225349775 12.25661251  NA   5.40469878
   7  stackoverflow 0.806526144   -1.32953625 -3.27038604  NA   -5.22846556
   8  please        -0.353515648  -0.4973664  4.21237923   NA   2.09939184
   9  help          -0.36372448   1.681068975 4.15631808   NA   2.15779412
   10 me            -1.17673216   0.44808555  -1.10209169  NA   -4.83515556
  </code></pre>
  <p><strong>Code:</strong></p>
  <pre><code> set.seed(12345)
   df &lt;- data.frame(id=c(&quot;this&quot;, &quot;is&quot;, &quot;an&quot;, &quot;example&quot;, &quot;data.frame&quot;, &quot;for&quot;, 
        &quot;stackoverflow&quot;, &quot;please&quot;, &quot;help&quot;, &quot;me&quot;), a=rnorm(10,0,0.4), b=rnorm(10,0,0.2), 
        d=rnorm(10,0,0.7), EE=rnorm(10,0,0.9), f=rnorm(10,0,0.5))
   weights &lt;- data.frame(V1=as.numeric(c(&quot;3.2&quot;, &quot;7.5&quot;, &quot;2.2&quot;, &quot;9.7&quot;, &quot;5.4&quot;, &quot;7.4&quot;, &quot;2.1&quot;, 
        &quot;5.0&quot;, &quot;3.3&quot;, &quot;7.6&quot;, &quot;3.6&quot;, &quot;7.7&quot;, &quot;7.1&quot;, &quot;3.3&quot;, &quot;9.8&quot;, &quot;9.2&quot;, &quot;2.5&quot;, &quot;6.2&quot;, &quot;4.1&quot;, &quot;8.7&quot;, 
        &quot;3.3&quot;, &quot;9.3&quot;, &quot;8.3&quot;)))
   rownames(weights) &lt;- paste(letters[1:23])
  </code></pre>