title: How to assign levels to a factor variable
body: <p>I have a data set in R with a column yr_renovated that has either 0 or a integer (i.e 1998)for the year a house was renovated in. How would i create a factor variable with the levels yes and no for if the house was renovated or not.</p>
  
  <pre><code>head(House_Data$yr_renovated,n=20)
  [1]    0    0    0    0    0    0    0    0    0    0    0    0 1998    0    0    0    0    0    0 
  </code></pre>
  
  <p>I was thinking of something along of lines of </p>
  
  <pre><code>levels(renovated)[levels(renovated) &lt;= 0] &lt;- "no"
  levels(renovated)[levels(renovated) &gt; 0] &lt;- "yes"
  </code></pre>
  
  <p>but i saw this used online and i dont know how exactly this works, also i realised that if i make a mistake in the assignment of levels lets say</p>
  
  <pre><code>levels(renovated)[levels(renovated) &lt;= 0] &lt;- "yes"
  levels(renovated)[levels(renovated) &gt; 0] &lt;- "yes"
  levels(renovated)[levels(renovated) &lt;= 0] &lt;- "no"
  </code></pre>
  
  <p>the last levels will not override the first one my only level will be yes, how would i remove that first wrongly assigned level? </p>
  
  <pre><code>no  no  no  no  no  no  no  no  no  no  no  no  yes no  no  no  no  no  no  no 
  Levels: no yes
  </code></pre>
  
  <p>This is what the final answer should look like or if using table()</p>
  
  <pre><code>renovated
    no  yes 
  5762  238 
  </code></pre>
  
  <p>but sometimes it will give me this result</p>
  
  <pre><code>renovated
   Yes 
  6000 
  </code></pre>
  
  <p>Excuse my rookie knowledge of R, we haven't worked much on R during our statistics module in university so far</p>