I was trying to my statistics homework using R when I ran into a problem with the sum() function. Given this vector:
-18.4, -5.4, 1.6, 5.6, 16.6
When I tried to use sum on the vector I got the following result:
2.220446e-15
If I do it a different way (the way I got that data) then I get another answer:
class2
[1] 65 78 85 89 100
class2mean
[1] 83.4
l<-class2-class2mean
sum(l)
[1] -2.842171e-14
l
[1] -18.4 -5.4 1.6 5.6 16.6
Obviously that answer is not correct. However when I tried to do the same calculation by 'hand' I got another result:
-18.4+-5.4+1.6+5.6+16.6
[1] 7.105427e-15
Finally I had to give up and just use my calculator. If anybody can provide me with some help or answers. Obviously I must be doing something wrong, but I do not know what and as this is such a fundamental function, I need to know how to use it correctly and effectively. Thank you!