title: Convert continuous numeric values to discrete categories defined by intervals
body: <p>I have a data frame with a continuous numeric variable, age in months (age_mnths). I want to make a new discrete variable, with age categories based on age intervals.</p>
  
  <pre><code># Some example data
  rota2 &lt;- data.frame(age_mnth = 1:170)
  </code></pre>
  
  <p>I've created <code>ifelse</code> based procedure (below), but I believe there is a possibility for more elegant solution. </p>
  
  <pre><code>rota2$age_gr&lt;-ifelse(rota2$age_mnth &lt; 6, rr2 &lt;- "0-5 mnths",
  
     ifelse(rota2$age_mnth &gt; 5 &amp; rota2$age_mnth &lt; 12, rr2 &lt;- "6-11 mnths",
  
            ifelse(rota2$age_mnth &gt; 11 &amp; rota2$age_mnth &lt; 24, rr2 &lt;- "12-23 mnths",
  
                   ifelse(rota2$age_mnth &gt; 23 &amp; rota2$age_mnth &lt; 60, rr2 &lt;- "24-59 mnths",
  
                          ifelse(rota2$age_mnth &gt; 59 &amp; rota2$age_mnth &lt; 167, rr2 &lt;- "5-14 yrs",
  
                                rr2 &lt;- "adult")))))
  </code></pre>
  
  <p>I know there is <code>cut</code> function but I couldn't deal with it for my purpose to discretize / categorize.</p>