How to split a continuous variable into intervals of equal length (defined number) and list the interval with cut points only in R? -


i divide set of data 4 equal size interval, e.g.:

x=c(0:10)  g1: [0,2.5)  g2: [2.5,5)  g3: [5,7.5)  g4: [7.5,10] 

is there anyway can split data intervals of equal length (say 4 in case) , below list including min , max values:

0   2.5   5   7.5   10  

thanks!

you're looking cut

cut(1:10, c(1, seq(2.5, 10, by=2.5)), include.lowest = t) #  [1] [1,2.5]  [1,2.5]  (2.5,5]  (2.5,5]  (2.5,5]  (5,7.5]  (5,7.5]  (7.5,10] #  [9] (7.5,10] (7.5,10] # levels: [1,2.5] (2.5,5] (5,7.5] (7.5,10] 

if want evenly spaced breaks, use seq

x <- 0:10 seq(min(x), max(x), len=5) # [1]  0.0  2.5  5.0  7.5 10.0 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -