title: How do I replace values in a vector when matching values exist in another vector in R?
body: <p>I have a vector that looks like this, lets call it gene_list:</p>
  
  <pre><code>"ENSMPUG00000000002" "ENSMPUG00000000003" "ENSMPUG00000000004" 
  "ENSMPUG00000000005" "ENSMPUG00000000006" "ENSMPUG00000000007"
  ....
  32057 items.
  </code></pre>
  
  <p>I have also the following, lets call it t1:</p>
  
  <pre><code> hgnc_symbol        ensembl_gene_id   
   Length:32057       Length:32057      
   Class :character   Class :character  
   Mode  :character   Mode  :character 
  </code></pre>
  
  <p>The head of t1 looks like:</p>
  
  <pre><code>hgnc_symbol    ensembl_gene_id
  1             ENSMPUG00000000002
  2             ENSMPUG00000000003
  3             ENSMPUG00000000004
  4             ENSMPUG00000000005
  5             ENSMPUG00000000006
  6      MAP2K3 ENSMPUG00000000007
  ....
  </code></pre>
  
  <p>What I want to do is replace the items in the first vector when a match is found in the second column of t1.  Note that many cases for the hgnc_symbol column are empty.  I only want to replace when the match is found in the second column and a value exists in the first.</p>
  
  <p>So in some r pseudocode, maybe something like</p>
  
  <pre><code>if t1$ensemble_gene_id[i] %in% gene_list 
      gene_list[i] = hgnc_symbol[i].
  </code></pre>
  
  <p>or</p>
  
  <pre><code>gene_list = gene_list[which(gene_list == t1$ensemble_gene_id)]
  </code></pre>
  
  <p>I know these aren't correct, just trying to convey what I want to achieve.  I know I could accomplish this in a loopy sort of way, but I'm also fairly sure there is a straightforward R-style way to do this in a line or two and am trying to adjust my R style.  I appreciate any input.  Thanks.</p>