title: Replace na in column by value corresponding to column name in seperate table
body: <p>I have a data frame which looks like this</p>
  
  <pre><code>data &lt;- data.frame(ID = c(1,2,3,4,5),A = c(1,4,NA,NA,4),B = c(1,2,NA,NA,NA),C= c(1,2,3,4,NA))
  
  &gt; data
    ID  A  B  C
  1  1  1  1  1
  2  2  4  2  2
  3  3 NA NA  3
  4  4 NA NA  4
  5  5  4 NA NA
  </code></pre>
  
  <p>I have a mapping file as well which looks like this</p>
  
  <pre><code>reference &lt;- data.frame(Names = c("A","B","C"),Vals = c(2,5,6))
  
  &gt; reference
    Names Vals
  1     A    2
  2     B    5
  3     C    6
  </code></pre>
  
  <p>I want my data file to be modified using the reference file in a way which would yield me this final data frame</p>
  
  <pre><code>&gt; final_data
    ID A B C
  1  1 1 1 1
  2  2 4 2 2
  3  3 2 5 3
  4  4 2 5 4
  5  5 4 5 6
  </code></pre>
  
  <p>What is the fastest way I can acheive this in R?</p>