I have a large list of matrices and a vector that identifies the desired matrices that I would like to rbind. However, I am stuck on how to get this to work. I have written some code below to illustrate my problem: # 3 simple matrices a<-matrix(1:9,3,3) b<-matrix(10:18,3,3) c<-matrix(19:27,3,3) #this is the type of list of matrices I am dealing with matrix.list<-vector("list",3) matrix.list[[1]]<-a matrix.list[[2]]<-b matrix.list[[3]]<-c #i have a vector that identifies the ones that i want desired.matrices <- c(1,3) #i have tried lots of things next but all fail. This one gets close but I seem to lose my dim attributes goal<-rbind(matrix.list[desired.matrices]) Any ideas would be wonderful. Thanks Heath -- *Heath Blackmon Graduate Teaching Assistant Dept of Biology - Box 19498 Univ. of Texas, Arlington Arlington, TX 76019 Office: ERB450 Phone 682-444-0538 * [[alternative HTML version deleted]]
?do.call ## as in do.call(rbind, list_of_matrices) ## Note that list_of_matrices must be a **list**. -- Bert On Thu, Mar 7, 2013 at 8:52 AM, Heath Blackmon <coleoguy at gmail.com> wrote:> I have a large list of matrices and a vector that identifies the desired > matrices that I would like to rbind. However, I am stuck on how to get > this to work. I have written some code below to illustrate my problem: > > # 3 simple matrices > a<-matrix(1:9,3,3) > b<-matrix(10:18,3,3) > c<-matrix(19:27,3,3) > > #this is the type of list of matrices I am dealing with > matrix.list<-vector("list",3) > matrix.list[[1]]<-a > matrix.list[[2]]<-b > matrix.list[[3]]<-c > > #i have a vector that identifies the ones that i want > desired.matrices <- c(1,3) > > #i have tried lots of things next but all fail. This one gets close but I > seem to lose my dim attributes > goal<-rbind(matrix.list[desired.matrices]) > > Any ideas would be wonderful. > > Thanks > > Heath > > -- > *Heath Blackmon > Graduate Teaching Assistant > Dept of Biology - Box 19498 > Univ. of Texas, Arlington > Arlington, TX 76019 > Office: ERB450 > Phone 682-444-0538 > * > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Not sure if this what you wanted. ?do.call(rbind,(matrix.list[desired.matrices])) #???? [,1] [,2] [,3] #[1,]??? 1??? 4??? 7 #[2,]??? 2??? 5??? 8 #[3,]??? 3??? 6??? 9 #[4,]?? 19?? 22?? 25 #[5,]?? 20?? 23?? 26 #[6,]?? 21?? 24?? 27 A.K. ________________________________ From: Heath Blackmon <coleoguy at gmail.com> To: r-help at r-project.org Sent: Thursday, March 7, 2013 11:52 AM Subject: [R] rbind a list of matrices I have a large list of matrices and a vector that identifies the desired matrices that I would like to rbind.? However, I am stuck on how to get this to work.? I have written some code below to illustrate my problem: # 3 simple matrices a<-matrix(1:9,3,3) b<-matrix(10:18,3,3) c<-matrix(19:27,3,3) #this is the type of list of matrices I am dealing with matrix.list<-vector("list",3) matrix.list[[1]]<-a matrix.list[[2]]<-b matrix.list[[3]]<-c #i have a vector that identifies the ones that i want desired.matrices <- c(1,3) #i have tried lots of things next but all fail.? This one gets close but I seem to lose my dim attributes goal<-rbind(matrix.list[desired.matrices]) Any ideas would be wonderful. Thanks Heath -- *Heath Blackmon Graduate Teaching Assistant Dept of Biology - Box 19498 Univ. of Texas, Arlington Arlington, TX 76019 Office: ERB450 Phone 682-444-0538 * ??? [[alternative HTML version deleted]] ______________________________________________ R-help at 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.
On 07-03-2013, at 17:52, Heath Blackmon <coleoguy at gmail.com> wrote:> I have a large list of matrices and a vector that identifies the desired > matrices that I would like to rbind. However, I am stuck on how to get > this to work. I have written some code below to illustrate my problem: > > # 3 simple matrices > a<-matrix(1:9,3,3) > b<-matrix(10:18,3,3) > c<-matrix(19:27,3,3) > > #this is the type of list of matrices I am dealing with > matrix.list<-vector("list",3) > matrix.list[[1]]<-a > matrix.list[[2]]<-b > matrix.list[[3]]<-c > > #i have a vector that identifies the ones that i want > desired.matrices <- c(1,3) > > #i have tried lots of things next but all fail. This one gets close but I > seem to lose my dim attributes > goal<-rbind(matrix.list[desired.matrices]) > > Any ideas would be wonderful.do.call(rbind,matrix.list) Berend