title: R - "find and replace" integers in a column with character labels
body: <p>I have two data frames the first (DF1) is similar to this:</p>
  
  <pre><code>Ba    Ram    You    Sheep
  30      1   33.2    120.9
  27      3   22.1    121.2
  22      4   39.1     99.1
  11      1   20.0    101.6
   9      3    9.8    784.3
  </code></pre>
  
  <p>The second (DF2) contains titles for column "Ram":</p>
  
  <pre><code>V1    V2
   1   RED
   2   GRN
   3   YLW
   4   BLU
  </code></pre>
  
  <p>I need to replace the DF1$Ram with corresponding character strings of DF2$V2:</p>
  
  <pre><code>Ba    Ram    You    Sheep
  30    RED   33.2    120.9
  27    YLW   22.1    121.2
  22    BLU   39.1     99.1
  11    RED   20.0    101.6
   9    YLW    9.8    784.3
  </code></pre>
  
  <p>I can do this with a nested for loop, but it feels REALLY inefficient:</p>
  
  <pre><code>x &lt;- c(1:nrows(DF1))
  y &lt;- c(1:4)
  for (i in x) {
      for (j in y) {
          if (DF1$Ram[i] == x) {
              DF1$Ram[i] &lt;- DF2$V2[y]
          }
      }
  }
  </code></pre>
  
  <p>Is there a way to do this more efficiently??!?! I know there is. I'm a noob.</p>