0

I have some code where I have bins that I place certain objects based on their score. If the score falls within certain a certain interval, it gets placed in a bin. For example,

If 0<x<=1 then object goes in bin 1
If 1<x<=2 then object goes in bin 2
If 2<x<=3 then object goes in bin 3

The problem arises that, if I run this code back to back, I get certain inconsistencies. For example, an object can be placed in bin 2 on the first run, and bin 3 on the second run. I believe these are boundary cases where the object has an x score very very close to 2, and on the first run it rounds it equal to 2 and places it in bin 2, and on the second run may round it differently, where x is now slightly larger than 2, and place it in bin 3.

How can I solve this problem?

PDS
  • 61
  • 5
  • use `?cut` or `?findInterval` instead or post a working example that demonstrates the problem – rawr Jun 24 '22 at 18:24
  • @AllanCameron Yes they are floats. I think this answers my question Allan – PDS Jun 24 '22 at 18:32
  • OK Andrew. Thanks for letting us know. I have closed as a duplicate for now. Feel free to post again if you are struggling to find a specific solution, using a reproducible example. – Allan Cameron Jun 24 '22 at 18:36

0 Answers0