Solved – How to cut a number into approximately equal parts and obtain those breaks?

Don't know how else to phrase this question.

Say I want to split a number (514) into 20 approximately equal parts, and I want to know what each number would be. So for example, if I want to split 10 into 3 parts, I would want something like 3, 6, 10.

I know I can do something somewhat similar to what I want with cut

unique(cut(1:514,breaks=20)) 

which gives me the following output

[1] (0.487,26.6] (26.6,52.3]  (52.3,77.9]  (77.9,104]   (104,129]    (129,155]    (155,181]    [8] (181,206]    (206,232]    (232,258]    (258,283]    (283,309]    (309,334]    (334,360]    [15] (360,386]    (386,411]    (411,437]    (437,463]    (463,488]    (488,515]    

I can see those are the approximate breaks, but how can I just get the 20 integers where the breaks are?

This might work well enough in many cases:

round(seq(1, 514, by = 514/20))[-1]

You could also use floor or ceiling in place of round if that gets closer. Think of it as counting by 514/20ths.

Similar Posts:

Rate this post

Leave a Comment