简体   繁体   中英

How the object size in R are calculated?

> print(object.size(runif(1e6)),unit="Mb")
7.6 Mb

This gives me 7.6Mb for a vector with 1 million elements. But why? each element is 32 bit or 64 bit? I cannot add these numbers up.

They're 64-bit (8-byte) floating point values. One megabyte (Mb) is 2^20 bytes (not 10^6 - see below) ... so ...

8*1e6/(2^20)
[1] 7.629395

Lots of potential for confusion about what Mb means:

As usual, this is clearly documented, deep in the details of ?object.size ...

As illustrated by below tables, the legacy and IEC standards use binary units (multiples of 1024), whereas the SI standard uses decimal units (multiples of 1000) ...

 *object size* *legacy* *IEC* \n   1 1 bytes 1 B   \n1024 1 Kb 1 KiB \n1024^2 1 Mb 1 MiB \n

Google's conversion appears to use SI units (1 MB = 10^6 bytes) instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM