0

I was making some code for a statistics class and when I was trying to sum the elements in a vector the answer was wrong. I was adding the elements in a data vector minus their mean, the output should be zero but R returns 8.12312e-14 (near to zero), this is the code:

X <- c(40, 62, 69, 77, 83, 88, 94, 101, 109, 115,
       123, 125, 128, 136, 137, 152, 152, 153, 160, 165)

sum(X-mean(X))

Actually I am new in R so I don't know what to try

  • See also [R FAQ 7.31](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f). – Rui Barradas Feb 22 '23 at 14:26

0 Answers0