Documentation for cut_width is a bit deceptive.
closed: One of "right" or "left" indicating whether right or left edges of bins are included in the bin.
Which is not true for the final bin, which is closed on the right regardless.
> a=runif(10, 0, 5)
> cut_width(a, width=0.5, center=0.25, closed="left")
[1] [2,2.5) [0.5,1) [0.5,1) [3,3.5) [1.5,2) [3.5,4] [2,2.5) [0,0.5) [2,2.5) [1.5,2)
Levels: [0,0.5) [0.5,1) [1,1.5) [1.5,2) [2,2.5) [2.5,3) [3,3.5) [3.5,4]
This causes issues when combining binned datasets where the bin intervals are the same, but the last bins are different.
Is there a simple solution? I want the final bin to be [3.5,4). I can think of kludgy ways to brute force it, but surely there is a better way.