Hello all, I have matrices V.i of dimension n.i x n.i, where i = 1, ..., J, and the sum of n.i equals N. (and n.i ! = n.j) goal: create one large matrix V, where V has matrices V.i on diagonal. I create each matrix V.i in a for loop (1 to J), so each time I'd like to augment V with the most recently calculated V.i, such that I'll have V after the final iteration of the for loop. question: how to initialize V and do the augmentation. any advice much appreciated. cheers, dave ps - please respond directly to afshar@miami.edu, thanks! [[alternative HTML version deleted]]
Have a look at adiag in the magic package. On 8/20/05, Afshartous, David <afshart at exchange.sba.miami.edu> wrote:> > Hello all, > > I have matrices V.i of dimension n.i x n.i, where i = 1, ..., J, and the sum of n.i equals N. (and n.i ! = n.j) > > goal: create one large matrix V, where V has matrices V.i on diagonal. > > I create each matrix V.i in a for loop (1 to J), so each time I'd like to augment V with the > most recently calculated V.i, such that I'll have V after the final iteration of the for loop. > > question: how to initialize V and do the augmentation. any advice much appreciated. > > cheers, > dave > > ps - please respond directly to afshar at miami.edu, thanks! > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
On Sat, 20 Aug 2005, Afshartous, David wrote:> I have matrices V.i of dimension n.i x n.i, where i = 1, ..., J, and the > sum of n.i equals N. (and n.i ! = n.j) > > goal: create one large matrix V, where V has matrices V.i on diagonal. > > I create each matrix V.i in a for loop (1 to J), so each time I'd like > to augment V with the most recently calculated V.i, such that I'll have > V after the final iteration of the for loop. > > question: how to initialize V and do the augmentation. any advice much > appreciated.It is probably best to pre-create a matrix and fill in the blocks. As in V <- matrix(0, N, N) # let n be a vector of what you called n.i n0 <- c(0, cumsum(n)) for(i in 1:J) { ind <- (n0[i]+1):n0[i+1] V[ind, ind] <- V.i }> > cheers, > dave > > ps - please respond directly to afshar at miami.edu, thanks!Please set that as your reply address to ease the lot of your helpers. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595