Binning a continuous variable into categorical ranges.
We can use the cut
function to create a new variable that categorizes income into the following ranges: <30, [30, 40), [40,50), [50, 60), 60+.
depress$inc_cut <- cut(depress$income, breaks=c(0, 30,40,50,60, 100))
table(depress$inc_cut)
##
## (0,30] (30,40] (40,50] (50,60] (60,100]
## 231 28 16 9 10