title: working with factors: reordering, relabeling and recoding in R
body: <p>I am having some trouble "factoring" a character variable and labeling/recoding the different levels. Is there an efficient way (i.e. less coding) to this with <code>tidyverse</code> or <code>Base R</code> such as <code>recode</code> or <code>fct_collapse</code> etc... Thank you</p>
  
  <pre><code>#This is what I have (a character variable)
  x &lt;- c("No", "Yes", "No2", "No3", "Maybe", "undecided", 
         "probably", "dont know", NA)
  x
  #I want a factor with three ordered levels as follows:
  
  #where No = c("No", "No2", "No3")
  #Yes = c("Yes")
  #other = c("Maybe", "undecided", "probably")
  #NA = c("dont know", NA)
  # and the levels would be 0 = "No",  1 = "Yes" and 2 = "Maybe"
  #that is:
  #xfact
  # [1] No    Yes   other
  # Levels: No Yes other
  #
  # as.integer(xfact)
  # [1] 0, 1, 2```
  </code></pre>