title: dplyr::mutate() return "Error in Ops.factor(gene_id$symbol, x) : level sets of factors are different"
body: <p>My data </p>
  
  <pre><code>gene_list &lt;- data.frame(mouse_gene = c("Ccnb1", "Cdk1", "Cdh3", "Cdkn1c"),
                      human_gene = c("SLCO2B1", "PPP1R3C", "MMP13", "CLEC6A"))
  
  gene_id &lt;- data.frame(gene_id = c("23334", "100001", "12341236", "34553433", "22998", "123121213"),
                    symbol = c("SLCO2B1", "PPP1R3C", "FX-232", "MMP13", "CLEC6A", "CSCCD"))
  </code></pre>
  
  <p>I want to add a column in gene_list that can find the corresponding gene_id of human_gene, so I defined a function</p>
  
  <pre><code>find_geneID &lt;- function(x){
        ID &lt;- gene_id[which(gene_id$symbol == x),1]
        return(ID)
  }
  </code></pre>
  
  <p>Then I use dplyr::mutate</p>
  
  <pre><code>gene_list &lt;- gene_list %&gt;% mutate(find_geneID(human_gene))
  </code></pre>
  
  <p>However, I get a return</p>
  
  <pre><code>Error in Ops.factor(gene_id$symbol, x) : level sets of factors are different
  </code></pre>
  
  <p>I know that I can use join in this case. However, I would like to know what should I do if I need to use a function in dplyr::mutate. </p>
  
  <p>Besides, sometimes when I want to use a value in one column, input into a function, and put into a new column, I will get </p>
  
  <pre><code>Column `new_column` must be length 568 (the number of rows) or one, not 2
  </code></pre>
  
  <p>Can someone tell me the reason? Thanks</p>