I have a dataset and I want to cut it into 4 parts using cut() function (or something similar).
set.seed(5)
cut(runif(100, 0, 100), 4)
gives levels: (1.35,25.8] (25.8,50.2] (50.2,74.6] (74.6,99]
The thing is, I want one interval to be (25.8,50] and another (50,74.6]. Actually, rest may vary a bit, but this 50 is important for me. How to achieve it?
If you are using cut, then the the first break has to be smaller than the min(data). Otherwise, there will be a NA in the intervals.
For example using quantiles,
cut(data, breaks= c(min(data) - diff(range(data)) / 1000,
quantile(data)[2:5]))
Also, you already know the two middle intervals (25.8 - 50 and 50 - 74.6), its then just finding the min and max of the data
cut(data, breaks= c(min(data) - diff(range(data)) / 1000,
25.8, 50, 74.6, max(data)))