Skip to content
Back to formatted view

Raw Message

Message-ID: <d9ad173c0903181914q72221505ofa0983f238241a95@mail.gmail.com>
Date: 2009-03-19T02:14:41Z
From: Kyeongmi Cheon
Subject: object size of a matrix and a list

Hello,
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.
Kyeongmi


My short test program is here:


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

   #list
   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