0

Using the cut function in R:

as.numeric(cut( 1:6,4))
## [1] 1 1 2 3 4 4

Is there a way to get it to cut the value in largest chunks first so that

as.numeric(cut( 1:6,4))

would return

## [1] 1 1 2 2 3 4

instead? and,

table(as.numeric(cut( 1:7,4)))

would return

## [1] 2 2 2 1

instead of

## [1] 2 2 1 2

etc…

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
user2821029
  • 153
  • 1
  • 3
  • 10
  • 2
    You can pass what ever `breaks=` you want based on your own rule (which isn't immediately clear from just two very specific examples). You can't change the default rule that `cut` uses however. Just create your own function that wraps cut with whatever you like. – MrFlick Oct 12 '18 at 01:14
  • It should chunk from start to end like in the example I gave – user2821029 Oct 12 '18 at 18:36
  • The way you use cut, equally spaced cut points are created, there is no "bigger chunk", what you might want it is equally sized groups : https://stackoverflow.com/questions/6104836/splitting-a-continuous-variable-into-equal-sized-groups . what you are asking for presents many edge cases though so we'd need much more comprehensive details and examples to help. Though you might want to look at dplyr::ntile – moodymudskipper Oct 13 '18 at 12:50

0 Answers0