R duplicate a matrix several times and then bind by rows together

user2157086 picture user2157086 · Oct 25, 2013 · Viewed 24k times · Source

I have the following matrix

FI1  FI2 YI1 YI2 BAL1 BAL2 GRO1 GRO2  EQ1  EQ2
1 0.22 0.15 0.1 0.1 0.05 0.05 0.05 0.05 0.05 0.05
2 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
3 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
4 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
5 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
6 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00

Now I would like to have this matrix duplicated 10 times and put in a matrix such that it looks like this (I just show it 2 times here)

FI1  FI2 YI1 YI2 BAL1 BAL2 GRO1 GRO2  EQ1  EQ2
1 0.22 0.15 0.1 0.1 0.05 0.05 0.05 0.05 0.05 0.05
2 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
3 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
4 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
5 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
6 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
1 0.22 0.15 0.1 0.1 0.05 0.05 0.05 0.05 0.05 0.05
2 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
3 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
4 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
5 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
6 0.22 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00

Can somebody propose me a simple way to accomplish this? Thanks Andreas

Answer

Matthew Plourde picture Matthew Plourde · Oct 25, 2013

Here's another way:

do.call(rbind, replicate(10, m, simplify=FALSE)) # where m is your matrix