manu p
manu p

Reputation: 985

Is this not how memory allocation works in R

I was testing how the RAM/memory allocation works in R. For example, the object size of Iris (150 rows) is 8.9 kb (I am assuming for 1 row it is 8.9/150). But for 1 row, the object size is 2.06 kb (How is it?) . Can anyone explain?

So is this not how allocation works. Total Memory = No of rows * memory / per each row

> object_size(iris)
8.9 kB
> object_size(head(iris,n = 1))
2.06 kB
> 2.06 * 150
[1] 309 kb

Upvotes: 0

Views: 24

Answers (1)

user2974951
user2974951

Reputation: 10375

Not quite, the dataframe itself takes quite a bit of memory, just the structure. Try this

> object.size(head(iris,n = 1))
1896 bytes
> object.size(head(iris,n = 2))
1928 bytes
> object.size(head(iris,n = 3))
2000 bytes

for a feeling.

Upvotes: 3

Related Questions