Hi, On Thu, Jan 20, 2011 at 6:59 AM, Maas James Dr (MED) <j.m...@uea.ac.uk> wrote: > I'm attempting to generalise a function that reads individual list > components, in this case they are matrices, and converts them into 3 > dimensional array. I can input each matrix individually, but want to do it > for about 1,000 of them ... > > This works > array2 <- abind(list1[[1]],list1[[2]],list1[[3]],along=3) > > This doesn't > array2 <- abind(list1[[1:3]],along=3)
This is close, but using the `[[` operator is not quite what you want here. myl <- rep(list(matrix(1:9, 3)), 9) length(myl) # look at the length of the list (9) myl[1:3] # select elements 1:3 of the list ## Contrast this with: myl[[1:2]] # select the 1st element of the list, then the 2nd element of that myl[[c(3, 1)]] # 3rd element of list, 1st element of that ## This does what you want I think require(abind) # load relevant package abind(myl[1:3], along = 3) Cheers, Josh > This doesn't either > array2 <- abind((list1[[1]]:(list1[[3]]),along=3) > > Any thoughts how I can make this work for larger numbers? > > Thanks > > J > > =============================== > Dr. Jim Maas > University of East Anglia > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.