Here is the answer for the second part: > lst=list(a1=matrix(rnorm(4),2,2), a2=matrix(rnorm(4),2,2),a3=matrix(rnorm(4),2,2)) > l.dim <- sapply(lst, dim) > l.dim a1 a2 a3 [1,] 2 2 2 [2,] 2 2 2 > all(l.dim[1,1] == l.dim[1,]) && all(l.dim[2,1] == l.dim[2,]) [1] TRUE > For the first part, why don't you just leave it a list and access the list elements by names? If you want to create new objects, the 'for' is fine.
On Mon, Jun 15, 2009 at 11:58 AM, Zhang,Yanwei <yanwei.zh...@cna.com> wrote: > Dear R users, > > I have two simple questions here, and hope someone can help me on this. > Thanks in advance. > > 1. > I have a list object lst=list(a1=matrix(rnorm(4),2,2), > a2=matrix(rnorm(4),2,2),a3=matrix(rnorm(4),2,2)). Here I only use three > elements for illustration, and in fact the length of lst, n, is unknown in > advance. I want to define an object for each element of this lst, and the > objects have names like "object1", "object2",...,"objectn". I could use a > loop like the following: > for (i in 1:length(lst)){ > assign(paste("object",i,sep=""),lst[[i]]) > } > > I wonder if there's a way to avoid this loop? > > > 2. > I want to validate whether all of the "object"s have the same dimension, > that is, whether dim(object1)[1]==dim(object2)[1]==dim(object3)[1]& > dim(object1)[2]==dim(object2)[2]==dim(object3)[2] is true. How can I do > that easily since the length of lst is not fixed? > > Thanks. > > Wayne (Yanwei) Zhang > Ttatistical *esearch > > CNA > > > > > > > > E-MAIL CONFIDENTIALITY NOTICE: The contents of this e-mail message and any > attachments are intended solely for the > addressee(s) and may contain confidential and/or legally privileged > information. If you are not the > intended recipient of this message or if this message has been addressed to > you in error, please > immediately alert the sender by reply e-mail and then delete this message > and any attachments. If you > are not the intended recipient, you are notified that any use, > dissemination, distribution, copying, or > storage of this message or any attachment is strictly prohibited. > > [[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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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.