title: How to recode variables in R
body: <p>I am trying to recode variables in an R dataframe. Example - variable X from my dataset contains 1's and 0's. I want to create another variables Y which recodes 1's &amp; 0's from X into Yes &amp; No respectively. </p>
  
  <p>I tried this to create the recoded Y variable:</p>
  
  <pre><code>w &lt;- as.character()
  
  for (i in seq_along(x))  {
      if (x[i] == 1)  {
          recode &lt;- "Yes"
      } else if (x[i] == 0)  {
          recode &lt;- "No"       
      }
      w &lt;- cbind(w, recode)
  }
  </code></pre>
  
  <p>Then I did this to line-up X and Y together:</p>
  
  <pre><code>y &lt;- c(x, y)
  </code></pre>
  
  <p>What I got back was this:</p>
  
  <pre><code> y
   # [1] "1"   "1"   "0"   "1"   "0"   "0"   "1"   "1"   "0"   "1"   "0"   "0"   "Yes" "Yes" "No"  "Yes" "No"  "No" 
  </code></pre>
  
  <p>I was expecting a dataframe with X &amp; Y columns.</p>
  
  <p>Question:</p>
  
  <ol>
  <li>How do I get X and Y into a dataframe?</li>
  <li>Is there a better way for recoding variables in a dataframe?</li>
  </ol>