hxd1011 hxd1011 - 1 year ago 40
R Question

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.

Answer Source

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

[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*
   1           1 bytes   1 B  
1024           1 Kb      1 KiB
1024^2         1 Mb      1 MiB

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download