posted 5 years ago
You can use the rep() function in several ways if you want to repeat the complete vector.
For examples: specify the argument times 1. To repeat the vector c(0, 0, 7) three times,
use this code:
> rep(c(0, 0, 7), times = 4)
[1] 0 0 7 0 0 7 0 0 7 0 0 7 2
We can also repeat every value by specifying the argument each, like this:
> rep(c(2, 4, 2), each = 2)
[1] 2 2 4 4 2 2 3
We can tell R for each value how often it has to repeat:
> rep(c(0, 7), times = c(4,3))
[1] 0 0 0 0 7 7 7 4
In seq, we use the argument length.out to define R. it will repeat the vector until it reaches that length,
even if the last repetition is incomplete.
> rep(1:3,length.out=9)
[1] 1 2 3 1 2 3 1 2 3