Consider a list as
list={1,2,3,4};
I can repeat the list n
times in this way
listRepeated=Flatten@Table[list, n];
Question 1: Can it be done in a faster way?
I also want to repeat each element n
times. For example, for n=3
the above list should become
listElementRepeated={1,1,1,2,2,2,3,3,3,4,4,4};
I can do this in this way
listElementRepeated=Flatten@Gather[listRepeated];
Question 2: Can it be done in a better and faster way?
Fold[Riffle[#1, list, #2] &, list, Range[2, 3]]
$\endgroup$