0

I am new to R and I am trying to create bins, 3 bins to be exact, for data that I have to sort. I need the first bin to collect values on the interval (-inf, -3] and be called "Improved", the second bin to collect values on the interval (-3, 3) and called "None", and I need the third bin to collect values on the interval [3, inf) called "Worsened". I tried using the cut function to no avail since all examples that I've come across have the closed interval on only one side and my intervals contain one interval with no closed intervals and two intervals with closed intervals on different sides.

Phil
  • 7,287
  • 3
  • 36
  • 66

1 Answers1

0

This can be achieved by installing and using the "fancycut" package.

In my case, this code worked:

new_name <- fancycut(x, Improved = '(-Inf, -3]', None = '(-3, 3)', Worsened = '[3, Inf)')

The fancycut package allows one to quite intuitively create intervals for bins as well as give them labels. Easy solution!