title: Combining factor level in R
body: <p>I would like combine level "A","B" into "A+B". I successfully did this by the following:</p>
  
  <pre><code>x &lt;- factor(c("A","B","A","C","D","E","A","E","C"))
  x
  #[1] A B A C D E A E C
  #Levels: A B C D E
  l &lt;- c("A+B","A+B","C","D+E","D+E")
  factor(l[as.numeric(x)])
  #[1] A+B A+B A+B C   D+E D+E A+B D+E C  
  #Levels: A+B C D+E
  </code></pre>
  
  <p>Is there any more trivial way to do this? (i.e. more explainable function name such as <strong>combine.factor(f, old.levels, new.levels)</strong> would help to understand the code easier.)</p>
  
  <p>Also, I try to find a well named function which probably work with data frame in <em>dplyr</em> package but no luck. The closest implementation is </p>
  
  <pre><code>df %&gt;% mutate(x = factor(l[as.numeric(x)]))
  </code></pre>