in trying to find the absolute distances (of a vector of values) from a number, and then converting these values into character, a value changed. I tried a naive search, unsuccessfully, but I'm not sure I know how to search on this subject.
An example:
abs(1.7 - seq(1, 2, 0.2))
#[1] 0.7 0.5 0.3 0.1 0.1 0.3
as.character(abs(1.7 - seq(1, 2, 0.2)))
#[1] "0.7" "0.5" "0.3" "0.0999999999999999" "0.1" "0.3"
as.character(1.7 - seq(1, 2, 0.2)) # same happens without abs() function
#[1] "0.7" "0.5" "0.3" "0.0999999999999999" "-0.1" "-0.3"
I tried on more examples but the as.character()
values are not always changed. Can someone explain what is happening?