In the code below, snapshot should be 0 if TrimCY = TrimBYS.
df <- df %>%
mutate(snapshot = case_when(Trend_direction != 2 ~ (TrimCY-TrimBYS)*sign(Trend_direction)*10/abs(Target_Snap-TrimBYS),
TRUE ~ 10-((abs(TrimCY-Target_Snap)*10)/abs(Target_Snap-TrimBYS))))
When I execute this code on the data displayed below, this is not always the case. See snapshot values.
Trend_direction Target_Snap TrimCY TrimBYS snapshot
1 56 53 53 0.000000e+00
1 56 54 54 -3.552714e-14
1 56 55 55 -7.105427e-14
Does anyone know why I am getting these very small non-zero results? When I copy the arithmetic function into the console and execute using the values above, it always comes out to 0.