Your example is hard to understand because it includes multiple copies of the number "1". Let me do something with different values and see if it gets what you are after. Your code as posted can't work because the variable n is not defined.
result <- list(a=array(1:48, dim=c(2,2,3,4)), b=array(49:96, dim=c(2,2,4,3))) result On Sun, Oct 28, 2012 at 7:01 PM, Loukia Spineli <spinelilouki...@gmail.com>wrote: > Dear all, > > I want to obtain the following result > > [[1]] > , , 1, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 2, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > ................ > > , , 9, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 10, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > > [[2]] > , , 1, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 2, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 3, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 4, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 5, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 1, 2 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 2, 2 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 3, 2 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > This is the code I have written. > t = c( 1 , 2, 2 ) > r<-as.vector(table(t)) > > mult<-vector("list",length(unique(t))) > for(i in 1:length(unique(t))){ > for(k in 1:r[i]){ > mult[[i]]<-array(1,dim=c(2,2,n[[i]][k],k)) > } > } > mult > > The results are correct for the array [[1]]. However for the array [[2]] I > get the following result: > [[2]] > , , 1, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 2, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 3, 1 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > , , 1, 2 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 2, 2 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > , , 3, 2 > > [,1] [,2] > [1,] 1 1 > [2,] 1 1 > > How could I correct the code? > > [[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]] ______________________________________________ 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.