title: Fast way to "translate" a column of variables in R using a lookup table
body: <p>starting to use R in my data analysis, but still a relative newbie. I have a data frame that looks like this:<br>
  <br>
  locations</p>
  
  <pre><code>loc IDnum
  100000001 1
  100000009 7
  100000021 3
  100000004 2
  100000017 3
  100000007 7
  100000067 5
  </code></pre>
  
  <p>and a matrix with a list of the ID numbers (from the second column) and the corresponding strings (like a translation table of sorts). </p>
  
  <p>Looks similar to this: <br>
  <br>
  names<br></p>
  
  <pre><code>IDnum   IDnames
  1  NNW43
  2  N3
  3  SE21
  4  SW54
  5  W6
  6  W12
  7  NE10
  ...
  </code></pre>
  
  <p>So this matrix is shorter because each ID number has a corresponding string, but in the original data frame there are more than one loc that contain the same IDnum.  </p>
  
  <p>I'm sure there is an easy way to match up each ID number with a string and create a new data frame with the first column the same but the second containing the strings instead of ID numbers, but I'm not sure what it is. All I know is that I'm told if you use loops in R you're doing it wrong. </p>
  
  <p>Result would be something like </p>
  
  <pre><code>loc name
  100000001 NNW43
  100000009 NE10
  100000021 SE21
  100000004 N3
  100000017 SE21
  100000007 NE10
  100000067 W6
  </code></pre>
  
  <p>I had a hard time figuring out how to title this question so any input on that would be useful as well.  Thanks in advance!  </p>
  
  <p><strong>EDITED to provide reproducible example</strong></p>