An example
mtcars$qsec
[1] 16.46 17.02 18.61 19.44 17.02 20.22 15.84 20.00 22.90 18.30 18.90 17.40
[13] 17.60 18.00 17.98 17.82 17.42 19.47 18.52 19.90 20.01 16.87 17.30 15.41
[25] 17.05 18.90 16.70 16.90 14.50 15.50 14.60 18.60
I want to stratify or group that variable. The point is I want to do it in the same steps (e.g. 5
).
Currently I would do it like that
mtcars$qsec_group[mtcars$qsec < 10] <- '10 or less'
mtcars$qsec_group[mtcars$qsec >= 10 & mtcars$qsec < 15] <- '10-15'
mtcars$qsec_group[mtcars$qsec >= 15 & mtcars$qsec < 20] <- '15-20'
It is quite unflexible. Is there an R-way to say Stratify that variable in steps of 5.?