I have a data frame with a column that contains percentage values in double format which I want to transform to an integer format. For example, 33% is currently represented as 0.33 and I want to change this to 33.
I have built a helper function that looks like this:
transform <- function(x) {
x <- x * 100
as.integer(x)
}
Now, if I run this, my rows with the value 0.33 get turned into 32 instead of 33. I have separated the multiplication to a line before as.integer(x)
, which correctly transforms my values to 33 (if I comment out as.integer(x)
). But if I run the whole function, the values get turned into 32.
Any ideas why this might happen and how to fix it? To my understanding, this has nothing to do with truncation of digits behind the dot, because the values are already correctly transformed to 33.