Sometimes you forget things. Here’s an example.

I wanted to test some features of the object.size function in R. I created a vector of a million observations and looked at its size. Depending on how I looked at the size, the results seemed inconsistent.

Here’s the R code.

```
> tst >- 1:1000000
object.size(tst)
4000040 bytes
> format(object.size(tst), "auto")
[1] "3.8 Mb"
```

So how come when you list the size in byes, it is slightly over 4 megabytes, but when you use the format function, the size shrinks to 3.8 megabytes?

Well, the answer is that a megabyte (2^20 bytes) is not a million bytes but rather 1,048,576 bytes. Divide 4,000,040 by 1,048,576 and you’ll see that the result is approximately 3.8.

I should have known that, but the reflexive divide by a million to convert bytes to megabytes is only an approximation to the truth.

This Blog post was added to the website on 2016-05-12 and was last modified on 2020-01-19. You can find similar pages at R software, Statistical computing.

An earlier version of this page appears here.