Binning data in one of the columns of a dataframe(Using R) I have a data frame that contains random values between 0-60 (inclusive 0 &amp; 60). These values denote months. I want to bin the data into three categories
(x&lt;=6, 6&lt; x &lt;=12, x>12) and generate a new single columns which will be a factor containing 3 values (0,1,2) denoting the respective bins.

I am able to generate 3 columns one-hot encoded style but I am unable to think of a way to generate single column having 3 factors.
Use cut:

&gt; df = data.frame(v=sample(1:60,1000,TRUE))
&gt; df$cat = cut(df$v,c(-Inf,6,12,Inf))
&gt; table(df$cat)

 (-Inf,6]    (6,12] (12, Inf] 
       97        92       811 


Also, simple R questions are better asked on StackOverflow.