0

Recently, I found something weird thing in my Rstudio. it is as follows: enter image description here

It is the output of the following code.

 data = iris[,-5]
 scaled_data = scale(data)
 colMeans(scaled_data)

I think the result of "colMeans(scaled_data)" is totally zero. But as you see, It is not a ZERO. Is there any solution for this problem? or any explanation for this? Thank you!

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
ainsuotain
  • 186
  • 2
  • 13
  • I just forgot to say "hello everyone" in the first line, And "edit" doesn't work so far:( – ainsuotain Nov 01 '19 at 16:48
  • 1
    May be `colMeans(scaled_data) <= .Machine$double.eps` – akrun Nov 01 '19 at 16:49
  • 2
    You can check the guidelines for asking [question](https://stackoverflow.com/help/how-to-ask) in case of any doubts. But, I think the "hello ..." is not required – akrun Nov 01 '19 at 16:52
  • Thank you for all. But what I am looking for is make the result of colMeans(scaled_data) = 0 0 0 0 – ainsuotain Nov 04 '19 at 12:15

1 Answers1

3

It is a floating point issue. You can refer floating point issue in R?

Simple fix is to use

round(colMeans(scaled_data),6)
prosoitos
  • 6,679
  • 5
  • 27
  • 41
  • 1
    Thank you for answering, but It is not that I am looking for. I am looking for something about options(). So after fixing, I want like this: colMeans(scaled_data)) = 0 0 0 0 – ainsuotain Nov 04 '19 at 12:14