title: Multiply rows (with row names) in one data frame with matching column names in another
body: <p>I have two data frames: </p>
  
  <pre><code>df1 &lt;- data.frame(Values=c(0.01,0.05), row.names=c("X", "Y"))
  df1
    Values
  X   0.01
  Y   0.05
  
  df2 &lt;-data.frame(c(0,1,1), c(1,0,0), c(1,1,1))
  colnames(df2) &lt;- c("X","Y","Z")
  
  df2
    X Y Z
  1 0 1 1
  2 1 0 1
  3 1 0 1
  </code></pre>
  
  <p>I wish to perform a <strong>rowwise</strong> operation on df2, where I multiply every <strong>column</strong> in df2 with its <strong>corresponding</strong> row in df1 and then perform a <strong>summation</strong>. </p>
  
  <p>For example, for row 1 of df2, I wish to calculate:  </p>
  
  <pre><code>df2 %&gt;% rowwise %&gt;% mutate(newVAL=(df1["X",]*df2[1,"X"])+(df1["Y",]*df2[1,"Y"]))
  </code></pre>
  
  <p>while excluding columns that don't match (rows in df1) or have NAs. </p>
  
  <p>I have several thousands of rows in df1 and several thousands of rows and columns in df2. </p>
  
  <p>Any help is much appreciated!! </p>
  
  <p>PS. I have implemented this in Perl using hashes and was using the system() call to perform these calculations within an Rmarkdown document. In order to keep it completely reproducible, I am trying to redo it in R. Happy to share the Perl code if necessary. </p>
  
  <p>Thanks. </p>