title: Warning: Mutate_impl(.data, dots): Unequal factor levels: coercing to character
body: <p>The Titanic Dataset can be downloaded from kaggle: kaggle.com/c/titanic/data. Please use the train.csv or install the package 'titanic' and use the dataset titanic_train.</p>
  
  <p>This works    </p>
  
  <pre><code>library(dplyr)
  library(stringr)
  
  titanic &lt;- titanic %&gt;%
      mutate(Cabin_Letter = ifelse(!is.na(Cabin), str_extract(Cabin, "[A-Z]+"), 'Unknown'))
  </code></pre>
  
  <p>This does not work entirely</p>
  
  <pre><code>titanic &lt;- titanic %&gt;%
      mutate(Cabin_Letter = factor(ifelse(!is.na(Cabin), str_extract(Cabin, "[A-Z]+"), 'Unknown')))
  </code></pre>
  
  <p>Warning:</p>
  
  <p>Warning messages:
  1: In mutate_impl(.data, dots) :
    Unequal factor levels: coercing to character
  2: In mutate_impl(.data, dots) :
    binding character and factor vector, coercing into character vector
  3: In mutate_impl(.data, dots) :
    binding character and factor vector, coercing into character vector
  4: In mutate_impl(.data, dots) :
    binding character and factor vector, coercing into character vector
  5: In mutate_impl(.data, dots) :
    binding character and factor vector, coercing into character vector
  6: In mutate_impl(.data, dots) :
    binding character and factor vector, coercing into character vector
  7: In mutate_impl(.data, dots) :
    binding character and factor vector, coercing into character vector</p>
  
  <p>How could I resolve this issue? I don't want to take the extra line:</p>
  
  <pre><code>titanic$Cabin_letter &lt;- factor(titanic$Cabin_letter)
  </code></pre>