Skip to content
Prev 360183 / 398503 Next

Trying to understand cut

The pitfalls of using `cut` has pushed me toward a preference for findIntervals

nums<-1:100
table( findInterval( nums ,  seq(0, 100, by=10) ) )

It does mean that I often need to construct names for my groups but at least I know that I will be getting left closed intervals by default, since its `rightmost.closed`-default is FALSE. I often flank my cutting sequence with -Inf on the left and Inf on the right to know that I am seeing any outliers:

table( findInterval( nums ,  c(-Inf, seq(10, 90, by=10), Inf)  )  ) # slightly different