Repeating a repeated sequence
Or, simpler (assuming you mean a vector, not an array)
rep(rep(1:4,each=3),3)
You can do it with a single rep
call. The each
and times
parameters are evaluated sequentially with the each
being done first.
rep(1:4, times=3, each=3) # 'each' done first regardless of order of named parameters
#[1] 1 1 1 2 2 2 3 3 3 4 4 4 1 1 1 2 2 2 3 3 3 4 4 4 1 1 1 2 2 2 3 3 3 4 4 4