set.seed(2) a=matrix(rnorm(400),ncol=100) #use a list aList<-list() for(i in 1:dim(a)[2]){ aList[[i]]<-matrix(a[,i],ncol=2) }
#get lots of variables for(i in 1:dim(a)[2]){ assign(paste("a",i,sep=""),matrix(a[,i],ncol=2)) } On 16.08.2012, at 08:07, bantex wrote: > Hi all, > > I have a 4 by 100 matrix. I wish to extract each column and make it into a 2 > by 2 matrix. > I also want to assign names for each 2X2 matrix. > For example > > set.seed(2) > a=matrix(rnorm(400),ncol=100) > a1=matrix(a[,1],ncol=2) > a2=matrix(a[,2],ncol=2) > . > . > . > a100=matrix(a[,100],ncol=2) > > Any simple ideas. Thanks. > > B > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Column-Extraction-from-matrix-tp4640465.html > Sent from the R help mailing list archive at Nabble.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. ______________________________________________ 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.