0

I'm trying to implement a categorization of a continuous variable into a categorical one, based on its interval within a dataframe in R.

My dataframe is shown below:

WIND_SPEED KWH
2.20 2000
3.30 4000
1.30 100
4.20 7000

So here is what I'd like to have: if the interval is from

  • [0-1) -> 1
  • [1-2) -> 2
  • [2-3) -> 3
  • and so on...

So getting the minimum value and the maximum the categorization should be increased by one for each interval that is of length one.

How can I achieve that in R?

asd-tm
  • 3,381
  • 2
  • 24
  • 41
Seniker96
  • 65
  • 7
  • 5
    It might be done using `ceiling(quux$WIND_SPEED)`. If, however, your intervals are not perfectly aligned like that, then you can use `cut` or `findInterval`. For instance, `1L+findInterval(quux$WIND_SPEED, 1:4)` returns `c(3L, 4L, 2L, 5L)`. – r2evans Mar 24 '23 at 16:57

0 Answers0