title: How can I convert dummy variables to factors in R?
body: <p>In my data frame (called survey) there is one variable called "answer"</p>
  
  <pre><code>    answer
        1
        2
        1
        2
  </code></pre>
  
  <p>I want to convert these dummy variables to </p>
  
  <pre><code>     answer
         NO
         YES
         NO
         YES
  </code></pre>
  
  <p>what command should I apply to survey$answer data?</p>
  
  <p>Actually what I want to do is to visualize the data with lattice</p>
  
  <pre><code>   barchart(as.factor(with(survey, survey$answer)))
  </code></pre>
  
  <p>The above command did result in a barchart, but I need to change the labels to "Yes" and "No" instead of "2" and "1". That's why I need to convert the dummy variables.</p>
  
  <p><img src="https://i.stack.imgur.com/hxxJIm.png" alt="enter image description here"></p>