I would like to create a vector that repeats itself. (eg 1:3 until 12 rows) 1,2,3,1,2,3,1,2,3,1,2,3
How can I do this in R?
Thanks for your help.
See ?rep
. What you want is as easy as
> rep(1:3, times = 4)
[1] 1 2 3 1 2 3 1 2 3 1 2 3
but if you don't know the length of the vector until run time but you do know the length of the output required, you could do (updated to reflect comment from @baptiste):
> rep(1:3, length.out = 12)
[1] 1 2 3 1 2 3 1 2 3 1 2 3