title: How to reduce Execution time to check the existence of a list element in R?
body: <p>I have few lists corresponding to several cell lines. Each list contains the expression values of around 5000 genes. For example</p>
  
  <pre><code>Gm12878 &lt;- list('gene1'= 3.14, 'gene4' = 1.11, 'gene10'= 1111,...)
  K562 &lt;- list('gene4'= 8.1, 'gene20'= 0.11, 'gene31'= 100,...)
  .
  .
  H1hESC &lt;- list('gene1'= 5.1, 'gene31'= 1.11, 'gene200'= 10,...)
  </code></pre>
  
  <p>The name of the cell lines is contained inside another list named Cells. The structure of Cells is</p>
  
  <pre><code>Cells[1] &lt;- "Gm12878"
  Cells[2] &lt;- "K562"
  .
  .
  Cells[5] &lt;- "H1hESC"
  </code></pre>
  
  <p>In another list I have the name of all genes. For example,</p>
  
  <pre><code>Genelist[1] &lt;- "gene1"
  Genelist[2] &lt;- "gene2"
  .
  .
  Genelist[15000] &lt;- "gene150050"
  </code></pre>
  
  <p>I want to check whether a gene, i.e. an element of Genelist (e.g. "gene10500") exists in a Cell line list or not.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Cells &lt;- list("Gm12878","K562", "H1hESC")
  
  for(i in 1:length(Genelist)){
    for(j in 1:length(Cells)){
      check_val &lt;- eval(parse(text=paste(c(Cells[j],"$`", annotation_list[i],"`"), collapse = "")))
      if(is.null(check_val)){
        print("FALSE")
        } else {
          print(check_val)
        }
    }
    }
  </code></pre>
  
  <p>Unfortunately, the code is taking very long time to execute if the Genelist is very long (in my case it is around 155000). Any suggestions on how to reduce the execution time?</p>