How to group vector values

Please familiarise yourself with the following:

Also, please use meaningful thread titles instead of "Need help" or something like that. That will significanty improve chance of answers from the menbers.


Now that moderation stuff is done, I'll share the following pointers, without providing any direct solution.

  1. You absolutely do not need tidyverse or data.table.
  2. There is no reason to use case_when of ifelse or if_else here, as there is no need to specify all intervals manually. In this particular case, cut function, suggested by Andrzej already, is perfect, and it comes from base R only.
  3. cut can be applied on vectors directly, no need to convert to data.frame or related classes.

Hope this helps.

1 Like