HI, set.seed(24) #creating the four matrix in a list lst1<-lapply(1:4,function(x) matrix(sample(1:40,20,replace=TRUE),ncol=5)) names(lst1)<- paste0("B",1:4) vec<- c(1,2,4,3,2,3,1) res<-do.call(rbind,lapply(vec,function(i) lst1[[i]])) dim(res) #[1] 28 5
#or B1<- lst1[[1]] B2<- lst1[[2]] B3<- lst1[[3]] B4<- lst1[[4]] res2<-do.call(rbind,lapply(vec,function(i) get(paste0("B",i)))) identical(res,res2) #[1] TRUE A.K. ----- Original Message ----- From: Preetam Pal <lordpree...@gmail.com> To: r-help@r-project.org Cc: Sent: Thursday, April 25, 2013 7:51 AM Subject: [R] Selecting and then joining data blocks Hi all, I have 4 matrices, each having 5 columns and 4 rows .....denoted by B1,B2,B3,B4. I have generated a vector of 7 indices, say (1,2,4,3,2,3,1} which refers to the index of the matrices to be chosen and then appended one on the top of the next: like, in this case, I wish to have the following mega matrix: B1over B2 over B4 over B3 over B2 over B3 over B1. 1> How can I achieve this? 2> I don't want to manually identify and arrange the matrices for each vector of index values generated (for which the code I used is : index=sample( 4,7,replace=T)). How can I automate the process? Basically, I am doing bootstrapping , but the observations are actually 4X5 matrices. Appreciate your help. Thanks, Preetam --- Preetam Pal (+91)-9432212774 M-Stat 2nd Year, Room No. N-114 Statistics Division, C.V.Raman Hall Indian Statistical Institute, B.H.O.S. Kolkata. [[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. ______________________________________________ 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.