Dear R users, I have a Hadamard matrix 16x15 and i want to put 16x5 submatrices in an array put i have an error.> A1<-matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,+ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, + 0,1,1,0,0,1,1,0,0,1,1,0,0,1,1, + 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0, + 0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, + 1,0,1,1,0,1,0,0,1,0,1,1,0,1,0, + 0,1,1,1,1,0,0,0,0,1,1,1,1,0,0, + 1,1,0,1,0,0,1,0,1,1,0,1,0,0,1, + 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1, + 1,0,1,0,1,1,0,1,0,1,0,1,0,0,1, + 0,1,1,0,0,1,1,1,1,0,0,1,1,0,0, + 1,1,0,0,1,0,1,1,0,0,1,1,0,1,0, + 0,0,0,1,1,1,1,1,1,1,1,0,0,0,0, + 1,0,1,1,0,0,1,1,0,1,0,0,1,1,0, + 0,1,1,1,1,0,0,1,1,0,0,0,0,1,1, + 1,1,0,1,0,1,0,1,0,0,1,0,1,0,1),ncol=15,byrow=T)> AA<-array(rep(0,240240),dim=c(16,5,3003)) > n<-0 > > > for (i in 1:11) {+ for (j in 2:12) { + for (k in 3:13) { + for (l in 4:14) { + for (m in 5:15) { + n<-n+1 + AA[,,n]<-cbind(A1[,i],A1[,j],A1[,k],A1[,l],A1[,m]) + } + } + } + } + } Error in AA[, , n] <- cbind(A1[, i], A1[, j], A1[, k], A1[, l], A1[, m]) : subscript out of bounds Any help wil be welcome!! [[alternative HTML version deleted]]
Hello, According to your script, the dimension of AA should be 16x3x161051. Best Regards, Pascal Le 30/10/2012 16:30, Haris Rhrlp a ?crit :> Dear R users, > > I have a Hadamard matrix 16x15 and i want to put 16x5 submatrices in an array put i have an error. > >> A1<-matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > + 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, > + 0,1,1,0,0,1,1,0,0,1,1,0,0,1,1, > + 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0, > + 0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, > + 1,0,1,1,0,1,0,0,1,0,1,1,0,1,0, > + 0,1,1,1,1,0,0,0,0,1,1,1,1,0,0, > + 1,1,0,1,0,0,1,0,1,1,0,1,0,0,1, > + 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1, > + 1,0,1,0,1,1,0,1,0,1,0,1,0,0,1, > + 0,1,1,0,0,1,1,1,1,0,0,1,1,0,0, > + 1,1,0,0,1,0,1,1,0,0,1,1,0,1,0, > + 0,0,0,1,1,1,1,1,1,1,1,0,0,0,0, > + 1,0,1,1,0,0,1,1,0,1,0,0,1,1,0, > + 0,1,1,1,1,0,0,1,1,0,0,0,0,1,1, > + 1,1,0,1,0,1,0,1,0,0,1,0,1,0,1),ncol=15,byrow=T) >> AA<-array(rep(0,240240),dim=c(16,5,3003)) >> n<-0 >> >> >> for (i in 1:11) { > + for (j in 2:12) { > + for (k in 3:13) { > + for (l in 4:14) { > + for (m in 5:15) { > + n<-n+1 > + AA[,,n]<-cbind(A1[,i],A1[,j],A1[,k],A1[,l],A1[,m]) > + } > + } > + } > + } > + } > Error in AA[, , n] <- cbind(A1[, i], A1[, j], A1[, k], A1[, l], A1[, m]) : > subscript out of bounds > > Any help wil be welcome!! > > [[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. >
(1) Think about what you are doing. (2) Try your ideas out with a *simple* example. For instance take A <- matrix(1:50,ncol=5). Then create all possible submatrices consisting of 3 distinct columns of A. There won't be nearly so many of these as in your real example, so the resulting output is not nearly so overwhelming. (3) Better still just do the nested forloops for this simple example, at each step printing out the triple of column indices (i,j,k). You will soon see what is going wrong in your real problem. cheers, Rolf Turner On 30/10/12 20:30, Haris Rhrlp wrote:> Dear R users, > > I have a Hadamard matrix 16x15 and i want to put 16x5 submatrices in an array put i have an error. > >> A1<-matrix(c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, > + 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1, > + 0,1,1,0,0,1,1,0,0,1,1,0,0,1,1, > + 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0, > + 0,0,0,1,1,1,1,0,0,0,0,1,1,1,1, > + 1,0,1,1,0,1,0,0,1,0,1,1,0,1,0, > + 0,1,1,1,1,0,0,0,0,1,1,1,1,0,0, > + 1,1,0,1,0,0,1,0,1,1,0,1,0,0,1, > + 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1, > + 1,0,1,0,1,1,0,1,0,1,0,1,0,0,1, > + 0,1,1,0,0,1,1,1,1,0,0,1,1,0,0, > + 1,1,0,0,1,0,1,1,0,0,1,1,0,1,0, > + 0,0,0,1,1,1,1,1,1,1,1,0,0,0,0, > + 1,0,1,1,0,0,1,1,0,1,0,0,1,1,0, > + 0,1,1,1,1,0,0,1,1,0,0,0,0,1,1, > + 1,1,0,1,0,1,0,1,0,0,1,0,1,0,1),ncol=15,byrow=T) >> AA<-array(rep(0,240240),dim=c(16,5,3003)) >> n<-0 >> >> >> for (i in 1:11) { > + for (j in 2:12) { > + for (k in 3:13) { > + for (l in 4:14) { > + for (m in 5:15) { > + n<-n+1 > + AA[,,n]<-cbind(A1[,i],A1[,j],A1[,k],A1[,l],A1[,m]) > + } > + } > + } > + } > + } > Error in AA[, , n] <- cbind(A1[, i], A1[, j], A1[, k], A1[, l], A1[, m]) : > subscript out of bounds > > Any help wil be welcome!! > > [[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.[[alternative HTML version deleted]]
Possibly Parallel Threads
- Diagonal Submatrices Extraction
- Creating 250 submatrices from a large single matrix with 2500 variables using loops
- Help with applying a function to all possible 2x2 submatrices
- Extraer elementos diagonales de submatrices
- Extraer elementos diagonales de submatrices