title: R convert numeric variable to factor
body: <p><strong>UPDATE</strong> I found solution to my problem, following code gives me correct answer</p>
  
  <pre><code>animaldata$myfac &lt;- with(animaldata, recode(Age.Intake, "lo:0=1; 1:hi=2; else=2"))
  animaldata$myfac = factor(animaldata$myfac)
  levels(animaldata$myfac) &lt;- list(young = 1, adult = 2)
  table(animaldata$myfac)
  
  young adult 
    191   282 
  </code></pre>
  
  <p><strong>This question is not a duplicate of there other question using cut</strong></p>
  
  <p>I am trying to convert a numerical variable to a factor based of condition on that variable. But I am unable to do so.</p>
  
  <pre><code>## load the librray
  library(SDSFoundations) 
  
  ## load the datset
  animaldata &lt;- AnimalData
  
  # Get age of each gender
  table(animaldata$Sex , animaldata$Age.Intake)
  </code></pre>
  
  <p>Running the above command gives the following result</p>
  
  <pre><code>           0   1   2   3   4   5   6   7   8   9  10  11  12  13  15  17
    Female  84  30  31  17  11  18   3   3   8   5   2   1   2   3   2   0
    Male   107  33  32  21  11  14  10  10   3   3   3   2   1   2   0   1
  </code></pre>
  
  <p>I want to create a factor variable <strong>Age</strong> with <strong>2 levels</strong> using the following conditions</p>
  
  <pre><code>If animaldata$Age.Intake &lt; 1 then young
  else adult
  </code></pre>
  
  <p>I have tried using <code>cut</code> but got in correct result</p>
  
  <pre><code>table(cut(animaldata$Age.Intake,breaks = c(0, 1, Inf), labels = c("young", "adult")))
  
  young adult 
     63   219 
  </code></pre>
  
  <p><strong>UPDATE 2</strong> I tried <code>include.lowest = TRUE</code> but I am still getting incorrect result.</p>
  
  <pre><code>table(cut(animaldata$Age.Intake,breaks = c(0, 1, Inf), labels = c("young", "adult"),include.lowest = TRUE))
  
  young =254 and adult= 219
  </code></pre>