[R] Duplicate rows of matrix

Sebastian P. Luque spluque at gmail.com
Fri Mar 9 18:38:22 CET 2007


On Fri,  9 Mar 2007 18:17:04 +0100,
"Bruno C\." <bruno.c at inwind.it> wrote:

> Hello my problem is the following: I have a matrix A and a vector B
> which contains as many rows as A.

> I need to build a matrix C which contains B[i]-times the row A[i,] and
> this for each line of A.

How about:


C <- A[rep(seq(nrow(A)), B), ]


Completely untested, because you didn't provide example code.


-- 
Seb



More information about the R-help mailing list