[R] object size of a matrix and a list

Kyeongmi Cheon katie.cheon at gmail.com
Thu Mar 19 03:14:41 CET 2009

My program calculates several variables at each iteration and some of them are

integers and the rest are numeric. When I save them into a matrix, all of them

are of numeric type, of course.

I'm trying to find a way to save time/memory of my program and I was thinking

that it might help to force some variables to be of integer type and the other

columns numeric type.

But when I actually tried it, I found it contrary. A list that has mixtures of

integers and doubles are larger in size than a matrix that has only doubles. Do

lists always take up more space than matrices if they have the same/similar

variables? I just want to know it for the sake of efficiency. Thank
you for your time.

My short test program is here:

   beta.mat <- matrix(0,nr=5, nc=2)
   for (i in 1:5){
      beta.mat[i,] <- c(i,i*10.0)

   gamma.mat <- list()
   for (i in 1:5){
      gamma.mat$aa[i] <- i
      gamma.mat$bb[i] <- i*10.0

   object.size(beta.mat) #240
   object.size(gamma.mat) #312

More information about the R-help mailing list