set.seed(1)
DATA = data.frame(X = sample(c(0:100), 1000, replace = TRUE))
DATA$CUT = with(DATA, cut(X, breaks = c(10,20,30,40,50,60,70,80,90), right = FALSE))
I wish to get groups: 0-9, 10-19, 20-29,..,80-89, 90+ but no matter how I do cut function I do not get these breaks.
You need to include the extreme bounds. For example
which results in
Since
cut()usually expects continuous values and not counts, if you have integers,[0,10)is the same as[0,9]or0-9If you want to set the labels, you can do
which now results in