0

I would like to create a variable ("ogive") to which certain values would be assigned depending on the value of the other variable ("new"). I need to set the intervals using the ifelse function.

I tried doing this and it didn't work

anton$ogive <- ifelse((anton$new >= 109 | anton$new <= 118) == 8, 
ifelse(anton$new >= 101 | anton$new <= 108) == 7,
ifelse(anton$new >= 91 | anton$new <= 100) == 6,
ifelse(anton$new >= 82 | anton$new <= 90) == 5,
ifelse(anton$new >= 76 | anton$new <= 81) == 4,
ifelse(anton$new >= 68 | anton$new <= 75) == 3)


Alexandra
  • 1
  • 1
  • 1
    you are not stating the *else* argument – Sotos May 14 '20 at 11:31
  • Could you please explain what exactly you're expecting the `ifelse()` to do here? – Dunois May 14 '20 at 11:32
  • This question is more fitting for the `cut` function. `cut(anton$new, breaks = c(68, 76, 82, 91, 101, 109, INF), right = FALSE, include.lowest = TRUE, labels = 3:8)`. In fairness that is a more fitting answer then the refered `This question already has an answer here`. – Oliver May 14 '20 at 11:36
  • 1
    @Oliver I agree. But I went with that target since OP mentions that they *have to use ifelse*. I added the `cut` though too. – Sotos May 14 '20 at 11:37
  • 1
    cut totally did what i was trying to achieve, thank you so much! – Alexandra May 14 '20 at 11:46

0 Answers0