[R] Data Structures

Randall Skelton rhskelto at atm.ox.ac.uk
Fri Nov 16 19:19:30 CET 2001

Hi all,

Thanks to everyone who replied to my change of case question... I doubt I
would have ever randomly guessed 'toupper' or 'tolower'.

I am trying to be cleaver[1] and make a flexible data structure in R.  I 
have a relatively large quantity of data that can be broadly grouped into 
blocks/chunks which are identical in their form:

  blockid = numeric
  blocktype = string
  dbname = string
  tblname = string
  quality = numeric
  errortype = numeric
  columnamount = data vector
  distr = data vector

I have grouped the above into a list as it contains mixed variable types.

Now is where things get a little more interesting... I have a large number
of the above blocks which I would like to assemble into an array of 
lists or perhaps a 'list of lists' (if I choose to include some other 
ancillary variables that apply to the global list structure).  Of course,
I am trying to do this generically in a function:

    for (i in 1:N) {
        # Get each data block
        block <- get.DataBlockFromDb(db,tbl,name);

where N is of unknown size (depends on the amount of data I am trying to
assimilate) and block is my list object from above.  I have tried to make
an array of list objects (like an array of structures in C?) but this
doesn't seem to work.  i.e.

        block[i] <- get.DataBlockFromDb(db,tbl,name);

where block is some form of a 1 dimensional array.

About the only thing I can seem to do is make a list of lists but I cannot
figure out how to create such a list in my for-loop construction above?  
Is there a function in R that would allow me to add/remove a new object to
an already defined list?  i.e. is it possible to 'grow' or 'shrink' a
previously defined list?  If nothing like this exists, is it *possible* to 
create a set of functions in R or C?


[1] I am using the term 'cleaver' rather loosely here-- especially given
the amount of time and thought this is taking.  What this really boils
down to is how to encapsulate complicated data structures in R so that I
can make an object and write code that then will act appropriately on the
object.  In my case, each block contains data which is not necessarily
taken from the same source and may be of completely different quality,
length, etc.  In this case, it isn't particularly clear to me how I can
invoke a standard 2 dimensional table (aka data frame). Am I missing 

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list