float_ints <- function(x) {
p <- mean(x)
q <- x - p
sum(q)
}
x <- c(1, 8, 2, 6, 3, 8, 7, 7, 7, 7)
float_ints(x)
#> [1] 3.552714e-15
This is what is known as a floating point error. For typeof double R carries out the decimal places just so far. For example, 2.99 is represented as
2.99
#> [1] 2.99
options(digits = 22)
2.99
#> [1] 2.990000000000000213163