Displaying 1 result from an estimated 1 matches for "rma1".
Did you mean:
rma
2007 Feb 28
1
Efficient way to repeat rows (or columns) of a matrix?
...9;d like to do the same sort of thing where I replace v_1 with a matrix, and
the jth row of the matrix is repeated i_1 times.
Obviously, I could do this with for loops, like the following:
>(ma1=matrix(1:6,nrow=2))
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
>vr1=c(2,3)
>rma1=NULL
>for(i in 1:length(vr1)){for(j in 1:vr1[i]){rma1=rbind(rma1,ma1[i,])}}
>rma1
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 1 3 5
[3,] 2 4 6
[4,] 2 4 6
[5,] 2 4 6
>
I just thought some of you clever programmers could show me a more efficient
way. (...