title: Adding a new column in R data frame with values conditional on values of another column
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12737146/assigning-values-to-a-dfcolumn-based-on-another-column-in-the-same-df">Assigning values to a df$column based on another column in the same df</a>  </p>
  </blockquote>
  
  
  
  <p>Suppose I have the data frame: </p>
  
  <pre><code>table&lt;- data.frame(population=c(100, 300, 5000, 2000, 900, 2500), habitat=c(1,2,3,4,5,6))
  </code></pre>
  
  <p>Now I want to add a new column table$size with the values 1 if population&lt; 500, 2 if 500&lt;=population&lt;1000, 3 if 1000&lt;=population&lt;2000, 4 if 2000&lt;=population&lt;3000, 5 if 3000&lt;=population&lt;=5000</p>
  
  <p>I only know how to create a column with a binary TRUE/FALSE outcome conditional on the values in another column , e.g.</p>
  
  <pre><code>table$size &lt;- (table$population&lt;1000) 
  </code></pre>
  
  <p>But I'm not sure to do it to get different numbers for different conditions. Can anyone provide help on this?</p>