For example I have a vector: a = my_function(1000)
!
head(a,15)
[1] 0.4011032 0.4867019 0.9831197 1.1138037 3.2740297 3.7853916 4.6833426 6.9224802 7.5878639
[10] 8.0706788 8.4404792 9.4149317 9.4176043 10.2345215 11.1884374
I want to use cut
function(or some alternative) to divide this vector into intervals. BUT I want, that maximum size of each interval will be, for example, 5.
EDITED:
breaks: breaks <- seq(from = 1, by = 4,length.out = 100)
So the first interval is: (1,5]
. And first seven variables of a
vector falls into this interval. But I want, that size of each intervall to be 5. It means that first 5 variables
[1] 0.4011032 0.4867019 0.9831197 1.1138037 3.2740297
lies in first interval. And variables 3.7853916 4.6833426
lies in second interval(with length equall 5).
How can I do that?
a
vector is your set of breaks, not an interval. First 10 are 1,6,13,19,25,31,37,43,49,55. How do those 10 fall in your interval(1,7]
? If you want a "number of elements that fall inside your interval" to be 5, then you should use a modulus and asort()
ororder()
subsequently to thecut()
orquantile()
function. If you want "the interval to be of size 5", then your question is definitely not very clear... since 7-2 = 5 and 13-7 = 6, you're using some example numbers that really muddy up your intentions. – quickreaction