title: Replacing items in a list with items from another list in R
body: <p>I have a column in a list with country codes in characters, I want to replace these with numeric codes. for the "decoding" I have a second list where the character country codes are associated with the numeric codes.</p>
  
  <p>I tried gsub:</p>
  
  <pre><code>   for (i in 1:nrow(countries))
  {gsub(countries$code3[i], countries$numcode[i], doc_report$nationality)}
  </code></pre>
  
  <p>I tried a for loop:</p>
  
  <pre><code>i &lt;- NULL
  n &lt;- NULL
  for (i in 1:nrow(doc_report)) {
    for (n in 1:nrow(countries)) {
      if(doc_report$nationality[i] == countries$code3[n])
        doc_report$nationality[i] &lt;- countries$numcode[n]
      else
        if(doc_report$nationality[i] == "NA")
        doc_report$nationality[i] &lt;- 000
    }
  }
  </code></pre>
  
  <p>and I had something in mind with merge()</p>
  
  <p>this is how the column looks like that has to be replaced</p>
  
  <pre><code>[nationality] IRL GBR ITA FRA POL BRA ESP GBR GBR GBR
  </code></pre>
  
  <p>this is how the second table for decoding looks like:</p>
  
  <pre><code> [code3] AFG ALB DZA ASM AGO AIA     ATG ARG ARM
   [numcode]   4   8  12  16  24 660  NA  28  32  51
  </code></pre>
  
  <p>so in table one I want the numcode from table 2 rather than the code3 style.</p>