# Building a new table by repeating elements from another table

I have a small problem that I cannot solve.

I have two tables, one with three elements:

a = {0, L/c, 2L/c};


and the other with 9 elements, all 0:

b = {0, 0, 0, 0, 0, 0, 0, 0, 0};


I would like to put the elements from table a into table b, giving so that I get the following table:

{0, L/c, 2L/c, 0, L/c, 2L/c, 0, L/c, 2L/c}


• Do you need b at all or do you simply want to generate a list of n repeated elements? Commented Jul 1, 2013 at 7:03

I don't know if b is something important, but if it is not:

a = {0, L/c, 2 L/c};


{0, L/c, (2 L)/c, 0, L/c, (2 L)/c, 0, L/c, (2 L)/c}

and if it is:

b = ConstantArray[0, 9];


{0, L/c, (2 L)/c, 0, L/c, (2 L)/c, 0, L/c, (2 L)/c}

a = {0, L/c, 2 L/c};
b = ConstantArray[0, 9];
Flatten[ConstantArray[a, Length[b]/Length[a]]]


Or, even more succinctly:

  b = Flatten[ConstantArray[{0, L/c, 2 L/c}, 3]]

• Just found out. Thank you very much bill Commented Jul 1, 2013 at 7:04
• @de_wight, if this answer has solved your problem, you should accept it by clicking on the check mark on the left. Commented Jul 1, 2013 at 7:36