title: Ifelse generating numeric values in r
body: <p>I know similar questions have been asked but I can't quite find the answer I'm looking for. I'm trying to match some characters across two columns in a dataframe:</p>
  
  <pre><code> num   orig   new   match
   1      p      p      T
   2      t      g      F
   3      p      b      F
   4      d      d      T
   5      g      g      T
  </code></pre>
  
  <p>I want to create a new column called 'final', and if 'match' is true, I want to copy the value from orig into it. If 'match' is false, I want to copy the value from 'new' into it. Should be easy! </p>
  
  <p>I use the code:</p>
  
  <pre><code> data &lt;- data %&gt;% mutate(final = ifelse(match == T, orig, new))
  </code></pre>
  
  <p>When I run this, everything in column 'final' turns numeric.</p>
  
  <p>I've also tried if_else, which generates the message "In <code>[&lt;-.factor</code>(<code>*tmp*</code>, i, value = c(13L, 13L, 2L, 13L, 13L, 4L,  :  invalid factor level, NA generated" and turns most of my FALSE values to NAs.</p>