[R] syntax for a list of components from a list
jwiley.psych at gmail.com
Thu Jan 20 16:20:11 CET 2011
On Thu, Jan 20, 2011 at 6:59 AM, Maas James Dr (MED) <J.Maas at 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[],list1[],list1[],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)
> This doesn't either
> array2 <- abind((list1[]:(list1[]),along=3)
> Any thoughts how I can make this work for larger numbers?
> Dr. Jim Maas
> University of East Anglia
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ph.D. Student, Health Psychology
University of California, Los Angeles
More information about the R-help