[R] array of lists? is this the best way to do it?

From: John McHenry <john_d_mchenry_at_yahoo.com>
Date: Wed 07 Dec 2005 - 00:37:26 EST


[Q.] How to create an array of lists, or structures the most elegant way?    

  There have been questions in the past but none too recently...I want to know if the following looks OK to you guys or if there is a better way to create an array of lists:    

   # PREAMBLE ... JUST TO GET THINGS GOING  makeList<- function(data, anythingElse) {   rval <- list( data = data,
    anythingElse = anythingElse
   )
  class(rval) <- "myListOfArbitraryThings"   return(rval)
 }
# make up some arbitrary data

 payload<- list( as.matrix(cbind(1,1:3)),    10:15,
   data.frame(cbind(x=1, y=1:10), fac=sample(LETTERS[1:3], 10, repl=TRUE))

        )    

   # HERE'S THE ARRAY-CONSTRUCTION PART THAT I WANT CRITIQUED:  n<- 3 # number of lists in the array of lists  v<- vector("list", n) # <--- IS THIS THE BEST WAY TO CREATE AN ARRAY OF LISTS?
# fill the array with essentially arbitrary stuff:
 for (i in 1:n) v[[i]]<- makeList(payload[[i]], i)        

  Thanks,    

  Jack.                      


        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Dec 07 01:04:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:29 EST