I have a dataframe with position in pos1 and sampling time in ts. In addition, I have a threshold / hysteresis that is on both sides (positive and negative).
n t.s. pos1 pos2 pos3 X side
1 0 0.0000000 0.000000 0.000000 NA MIDDLE
2 78 -0.4541016 1.430664 1.430664 NA MIDDLE
3 109 -0.4199219 1.430664 1.430664 NA MIDDLE
4 147 -0.4150391 1.430664 1.430664 NA MIDDLE
5 197 -0.4345703 1.430664 1.425781 NA MIDDLE
6 247 -0.4541016 1.430664 1.430664 NA MIDDLE
In this case, hysteresis = 0.5 / -0.5. There is a light that turns on as soon as pos1> Hysteresis, and it will not turn until pos1 <-0.5. To do this, I created an added variable in my framework (side) that tells me that pos1 is above 0.5 (ON), between 0.5 and -0.5 (in the middle) or below -0.5 (OFF )
I would like to make a variable (let it be light) that has only two possibilities ON / OFF. To do this, I need to assign from average to one of two, and this depends on the last different side factor (ON / OFF).
I am having trouble finding a function that found previous variables after the middle condition was met.
source
share